Exemplo n.º 1
0
        public void Initialize(DateTime dateTime)
        {
            now = dateTime;

            // 満月基準日を 2018/08/01 01:55 とする(wiki より)
            DateTime reference = new DateTime(2018, 8, 1, 1, 55, 0);
            // 現在時刻との差を求める
            TimeSpan span = Now.Subtract(reference);
            // 分に換算
            double min = span.TotalMinutes;
            // 118 で割って切り捨て
            int div = (int)Math.Floor(min / INTERVAL_MINUTES);

            // 最終満月を求める
            LastFullMoon = reference.AddMinutes(INTERVAL_MINUTES * div);

            // タイマー用の設定
            lastMessage = LastFullMoon.AddMinutes(MESSAGE_MINUTES);
            lastSnooze  = LastFullMoon.AddMinutes(SNOOZE_MINUTES);
            lastEnded   = LastFullMoon.AddMinutes(TEN_MINUTES);
        }
Exemplo n.º 2
0
        // 1 秒毎に実行
        void Refresh()
        {
            // 最終満月 + 118 分を越えたら 1 周したことになる
            if (LastFullMoon.AddMinutes(INTERVAL_MINUTES) <= Now)
            {
                LastFullMoon = LastFullMoon.AddMinutes(INTERVAL_MINUTES);
            }

            #region 月齢 判定(ダサいしw)

            if (Now < LastFullMoon.AddMinutes(TEN_MINUTES))
            {
                MoonAge = MoonAges.Full;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES))
            {
                MoonAge = MoonAges.F7N;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 2))
            {
                MoonAge = MoonAges.F6N;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 3))
            {
                MoonAge = MoonAges.F5N;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 4))
            {
                MoonAge = MoonAges.F4N;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 5))
            {
                MoonAge = MoonAges.F3N;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 6))
            {
                MoonAge = MoonAges.F2N;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7))
            {
                MoonAge = MoonAges.F1N;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7)
                     .AddMinutes(TEN_MINUTES))
            {
                MoonAge = MoonAges.New;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7)
                     .AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES))
            {
                MoonAge = MoonAges.N1F;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7)
                     .AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 2))
            {
                MoonAge = MoonAges.N2F;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7)
                     .AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 3))
            {
                MoonAge = MoonAges.N3F;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7)
                     .AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 4))
            {
                MoonAge = MoonAges.N4F;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7)
                     .AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 5))
            {
                MoonAge = MoonAges.N5F;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7)
                     .AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 6))
            {
                MoonAge = MoonAges.N6F;
            }
            else if (Now < LastFullMoon.AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7)
                     .AddMinutes(TEN_MINUTES).AddMinutes(SEVEN_MINUTES * 7))
            {
                MoonAge = MoonAges.N7F;
            }
            else
            {
                MoonAge = MoonAges.none;    // エラーのような気がするけどなぁ
            }

            #endregion
        }
Exemplo n.º 3
0
        void CalcMessage()
        {
            string hhmm = "yyyyMMddHHmm";

            // 5 分前及び 1 分前の判定

            DateTime before5min =
                LastFullMoon
                .AddMinutes(INTERVAL_MINUTES)
                .AddMinutes(-5);

            if (Now.ToString(hhmm) == before5min.ToString(hhmm))
            {
                if (lastMessage.ToString(hhmm) != before5min.ToString(hhmm))
                {
                    lastMessage  = Now;
                    IsBefore5min = true;
                }
                else
                {
                    IsBefore5min = false;
                }

                if (Now < before5min.AddSeconds(DURING_5MIN_SECONDS))
                {
                    During5minMessage = true;
                }
                else
                {
                    During5minMessage = false;
                }
            }
            else
            {
                IsBefore5min      = false;
                During5minMessage = false;
            }

            DateTime before1min =
                LastFullMoon
                .AddMinutes(INTERVAL_MINUTES)
                .AddMinutes(-1);

            if (Now.ToString(hhmm) == before1min.ToString(hhmm))
            {
                if (lastSnooze.ToString(hhmm) != before1min.ToString(hhmm))
                {
                    lastSnooze   = Now;
                    IsBefore1min = true;
                }
                else
                {
                    IsBefore1min = false;
                }

                if (Now < before1min.AddSeconds(DURING_1MIN_SECONDS))
                {
                    During1minMessage = true;
                }
                else
                {
                    During1minMessage = false;
                }
            }
            else
            {
                IsBefore1min      = false;
                During1minMessage = false;
            }

            // 終了の判定

            DateTime ended =
                LastFullMoon
                .AddMinutes(TEN_MINUTES);

            if (Now.ToString(hhmm) == ended.ToString(hhmm))
            {
                if (lastEnded.ToString(hhmm) != ended.ToString(hhmm))
                {
                    lastEnded       = Now;
                    IsFullmoonEnded = true;
                }
                else
                {
                    IsFullmoonEnded = false;
                }

                if (Now < ended.AddSeconds(DURING_ENDED_SECONDS))
                {
                    DuringEndedMessage = true;
                }
                else
                {
                    DuringEndedMessage = false;
                }
            }
            else
            {
                IsFullmoonEnded    = false;
                DuringEndedMessage = false;
            }
        }