aboutsummaryrefslogtreecommitdiffstats
path: root/WarframeClock/Clock.cs
blob: 956cfaa5f19f0870a39188a319fad24211f1a309 (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
using System;

namespace WarframeClock
{
    public static class Clock
    {
        public static long? CetusExpiry { get; set; }

        public static string CetusExpiryString()
        {
            double currentTime = GetCurrentTime();
            double cetusLen = 8998.8748, cetusDayLen = cetusLen * 2 / 3;
            double cetusBegin = (CetusExpiry ?? 1548159123053) / 1000.0 - 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 = 1548148830; // 2019-01-22 09:20:30 +0000
            dayStart += Math.Floor((currentTime - dayStart) / 1600) * 1600;

            if (currentTime - dayStart < 467)
                return $"Vallis: ❄️[→☁] {GetReadableTimeSpan(dayStart + 467 - 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";
    }
}