aboutsummaryrefslogtreecommitdiffstats
path: root/WarframeClock/Clock.cs
blob: 688781beb75dc811efa1795d2651db9a394efe69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;

namespace WarframeClock
{
    public static class Clock
    {
        public static long CetusExpiry { get; set; } = -1;

        public static string CetusExpiryString()
        {
            double currentTime = GetCurrentTime();
            double cetusLen = 8998.8748;
            double cetusDayLen = 8248.9686 - 2249.7187;
            double cetusBegin = 1509371722 + 2249.7187;

            if (CetusExpiry >= 0)
            {
                cetusBegin = CetusExpiry / 1000 - cetusLen;
            }
            cetusBegin += Math.Floor((currentTime - cetusBegin) / cetusLen) * cetusLen;

            if (currentTime < cetusBegin + cetusDayLen)
                return $"Plains: ☀ {GetReadableTimeSpan(cetusBegin + cetusDayLen - currentTime)}";
            else
                return $"Plains: 🌙 {GetReadableTimeSpan(cetusBegin + cetusLen - currentTime)}";
        }

        public static string VallisExpiryString()
        {
            double currentTime = GetCurrentTime();
            double dayStart = 1542131224;
            dayStart += Math.Floor((currentTime - dayStart) / 1600) * 1600;

            if (currentTime - dayStart < 400)
                return $"Vallis: ❄️[→☁] {GetReadableTimeSpan(dayStart + 400 - currentTime)}";
            else if (currentTime - dayStart < 800)
                return $"Vallis: ☁[→🌣] {GetReadableTimeSpan(dayStart + 800 - currentTime)}";
            else if (currentTime - dayStart < 1200)
                return $"Vallis: 🌣[→☁] {GetReadableTimeSpan(dayStart + 1200 - currentTime)}";
            else
                return $"Vallis: ☁[→❄️] {GetReadableTimeSpan(dayStart + 1600 - currentTime)}";
        }

        private static double GetCurrentTime() =>
            DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds / 1000;

        private static string GetReadableTimeSpan(double span) =>
            $"{Math.Floor(span / 60)}m{Math.Floor(span % 60)}s";
    }
}