Ejemplo n.º 1
0
        public void ToDateTimeOffset()
        {
            var utc = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);

            Assert.Equal(new DateTimeOffset(2018, 5, 6, 11, 22, 33, 111, TimeSpan.Zero),
                         utc.ToDateTimeOffset());
        }
Ejemplo n.º 2
0
        public void OneBillionTest()
        {
            using var toolStrip = new TestToolStripAPIGauge();

            var now = new DateTimeUtc(2020, 2, 25, 19, 0, 0);

            toolStrip.DateTimeNow = now;

            toolStrip.AutoSize    = false;
            toolStrip.Size        = new Size(100, 10);
            toolStrip.GaugeHeight = 5;

            MyCommon.TwitterApiInfo.AccessLimit["/statuses/user_timeline"] = new ApiLimit(
                limitCount: 1_000_000_000,
                limitRemain: 999_999_999,
                resetDate: now + TimeSpan.FromMinutes(15)
                );
            toolStrip.ApiEndpoint = "/statuses/user_timeline";

            Assert.Equal(new Rectangle(0, 0, 99, 5), toolStrip.apiGaugeBounds);   // 99% (999999999/1000000000)
            Assert.Equal(new Rectangle(0, 5, 100, 5), toolStrip.timeGaugeBounds); // 100% (15/15)
            Assert.Equal("API 999999999/1000000000", toolStrip.Text);
            Assert.Equal("API rest /statuses/user_timeline 999999999/1000000000" + Environment.NewLine + "(reset after 15 minutes)", toolStrip.ToolTipText);

            MyCommon.TwitterApiInfo.AccessLimit.Clear();
        }
Ejemplo n.º 3
0
        public void ToLocalTimeString_FormatTest()
        {
            var localDatetime = new DateTime(2018, 5, 6, 11, 22, 33, 111, DateTimeKind.Local);
            var utc           = new DateTimeUtc(localDatetime.ToUniversalTime());

            Assert.Equal(localDatetime.ToString("O"), utc.ToLocalTimeString("O"));
        }
Ejemplo n.º 4
0
        public void Constructor_DateTest()
        {
            var utc = new DateTimeUtc(2018, 5, 6);

            Assert.Equal(new DateTime(2018, 5, 6, 0, 0, 0, 0, DateTimeKind.Utc),
                         utc.ToDateTimeUnsafe());
        }
Ejemplo n.º 5
0
        public void ToLocalTimeString_Test()
        {
            var datetime = new DateTime(2018, 5, 6, 11, 22, 33, 111, DateTimeKind.Local);
            var utc      = new DateTimeUtc(datetime.ToUniversalTime());

            Assert.Equal(datetime.ToString(), utc.ToLocalTimeString());
        }
Ejemplo n.º 6
0
        public void Constructor_DateAndTimeMillisecondsTest()
        {
            var utc = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 456);

            Assert.Equal(new DateTime(2018, 5, 6, 11, 22, 33, 456, DateTimeKind.Utc),
                         utc.ToDateTimeUnsafe());
        }
Ejemplo n.º 7
0
        public void ToString_Test()
        {
            var datetime = new DateTime(2018, 5, 6, 11, 22, 33, 111, DateTimeKind.Utc);
            var utc      = new DateTimeUtc(datetime);

            Assert.Equal(datetime.ToString(), utc.ToString());
        }
Ejemplo n.º 8
0
        public void TryParseExact_Test(string input, string format, bool expectedParsed, DateTimeUtc expectedResult)
        {
            var parsed = DateTimeUtc.TryParseExact(input, new[] { format }, DateTimeFormatInfo.InvariantInfo, out var result);

            Assert.Equal(expectedParsed, parsed);
            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 9
0
        public void ToLocalTime()
        {
            var utc      = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var expected = new DateTimeOffset(2018, 5, 6, 11, 22, 33, 111, TimeSpan.Zero).ToLocalTime();

            Assert.Equal(expected, utc.ToLocalTime());
        }
Ejemplo n.º 10
0
        public void Constructor_DateTimeTest()
        {
            var datetime = new DateTime(2018, 5, 6, 11, 22, 33, DateTimeKind.Utc);
            var utc      = new DateTimeUtc(datetime);

            Assert.Equal(datetime, utc.ToDateTimeUnsafe());
        }
Ejemplo n.º 11
0
        public void FromUnixTime_Test()
        {
            var utc = DateTimeUtc.FromUnixTime(1234567890);

            Assert.Equal(new DateTime(2009, 2, 13, 23, 31, 30, 0, DateTimeKind.Utc),
                         utc.ToDateTimeUnsafe());
        }
Ejemplo n.º 12
0
        public void Constructor_DateTimeOffsetTest()
        {
            var datetimeOffset = new DateTimeOffset(2018, 5, 6, 11, 22, 33, 456, TimeSpan.FromHours(9));
            var utc            = new DateTimeUtc(datetimeOffset);

            Assert.Equal(new DateTime(2018, 5, 6, 2, 22, 33, 456, DateTimeKind.Utc),
                         utc.ToDateTimeUnsafe());
        }
Ejemplo n.º 13
0
        public void OperatorMinus_TimeSpanTest()
        {
            var utc  = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var diff = TimeSpan.FromDays(1);

            Assert.Equal(new DateTime(2018, 5, 5, 11, 22, 33, 111, DateTimeKind.Utc),
                         (utc - diff).ToDateTimeUnsafe());
        }
Ejemplo n.º 14
0
        public void GetHashCode_Test()
        {
            var utc1 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var utc2 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var utc3 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 222);

            Assert.Equal(utc1.GetHashCode(), utc2.GetHashCode());
            Assert.NotEqual(utc1.GetHashCode(), utc3.GetHashCode());
        }
Ejemplo n.º 15
0
        public void OperatorMinus_DateTimeTest()
        {
            var utc1 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var utc2 = new DateTimeUtc(2018, 5, 7, 11, 22, 33, 111);

            Assert.Equal(TimeSpan.Zero, utc1 - utc1);
            Assert.Equal(TimeSpan.FromDays(-1), utc1 - utc2);
            Assert.Equal(TimeSpan.FromDays(1), utc2 - utc1);
        }
Ejemplo n.º 16
0
        public void CompareTo_Test()
        {
            var utc1 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var utc2 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var utc3 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 222);

            Assert.Equal(0, utc1.CompareTo(utc2));
            Assert.True(utc1.CompareTo(utc3) < 0);
            Assert.True(utc3.CompareTo(utc1) > 0);
        }
Ejemplo n.º 17
0
        public void Equals_Test()
        {
            var utc1 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var utc2 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var utc3 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 222);

            Assert.True(utc1.Equals(utc2));
            Assert.True(utc1.Equals((object)utc2));

            Assert.False(utc1.Equals(utc3));
            Assert.False(utc1.Equals((object)utc3));
        }
Ejemplo n.º 18
0
        public void OperatorEqual_Test()
        {
            var utc1 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var utc2 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 222);

#pragma warning disable CS1718
            Assert.True(utc1 == utc1);
            Assert.False(utc1 == utc2);

            Assert.False(utc1 != utc1);
            Assert.True(utc1 != utc2);
#pragma warning restore CS1718
        }
Ejemplo n.º 19
0
        public void Invoke()
        {
            this.lastInvoked = DateTimeUtc.Now;

            if (this.refreshTimerEnabled == TIMER_DISABLED)
            {
                lock (this.throttlingTimer)
                {
                    if (Interlocked.CompareExchange(ref this.refreshTimerEnabled, TIMER_ENABLED, TIMER_DISABLED) == TIMER_DISABLED)
                    {
                        this.throttlingTimer.Change(dueTime: 0, period: Timeout.Infinite);
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public static DateTimeUtc DateTimeParse(string input)
        {
            var formats = new[] {
                "ddd MMM dd HH:mm:ss zzzz yyyy",
                "ddd, d MMM yyyy HH:mm:ss zzzz",
            };

            if (DateTimeUtc.TryParseExact(input, formats, DateTimeFormatInfo.InvariantInfo, out var result))
            {
                return(result);
            }

            TraceOut("Parse Error(DateTimeFormat) : " + input);

            return(DateTimeUtc.Now);
        }
Ejemplo n.º 21
0
        private async void Execute(object _)
        {
            var timerExpired = this.lastInvoked < this.lastExecuted;

            if (timerExpired)
            {
                // 前回実行時より後に lastInvoked が更新されていなければタイマーを止める
                Interlocked.CompareExchange(ref this.refreshTimerEnabled, TIMER_DISABLED, TIMER_ENABLED);
            }
            else
            {
                this.lastExecuted = DateTimeUtc.Now;

                await this.timerCallback().ConfigureAwait(false);

                // dueTime は Execute が呼ばれる度に再設定する (period は使用しない)
                // これにより timerCallback の実行に Interval 以上の時間が掛かっても重複して実行されることはなくなる
                lock (this.throttlingTimer)
                    this.throttlingTimer.Change(dueTime: (int)this.Interval.TotalMilliseconds, period: Timeout.Infinite);
            }
        }
Ejemplo n.º 22
0
        public void OperatorCompare_Test()
        {
            var utc1 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);
            var utc2 = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 222);

#pragma warning disable CS1718
            Assert.False(utc1 < utc1);
            Assert.True(utc1 < utc2);
            Assert.False(utc2 < utc1);

            Assert.True(utc1 <= utc1);
            Assert.True(utc1 <= utc2);
            Assert.False(utc2 <= utc1);

            Assert.False(utc1 > utc1);
            Assert.False(utc1 > utc2);
            Assert.True(utc2 > utc1);

            Assert.True(utc1 >= utc1);
            Assert.False(utc1 >= utc2);
            Assert.True(utc2 >= utc1);
#pragma warning restore CS1718
        }
Ejemplo n.º 23
0
        public void FormatQuoteTweetHtml_PostClassTest()
        {
            var post = new PostClass
            {
                StatusId   = 12345L,
                Nickname   = "upsilon",
                ScreenName = "kim_upsilon",
                Text       = "<a href=\"https://twitter.com/twitterapi\">@twitterapi</a> hogehoge",
                CreatedAt  = new DateTimeUtc(2015, 3, 30, 3, 30, 0),
            };

            // PostClass.Text はリンクを除去するのみでエスケープは行わない
            // (TweetFormatter によって既にエスケープされた文字列が格納されているため)

            var expected = "<a class=\"quote-tweet-link\" href=\"//opentween/status/12345\">" +
                           "<blockquote class=\"quote-tweet\">" +
                           "<p>@twitterapi hogehoge</p> &mdash; upsilon (@kim_upsilon) " + DateTimeUtc.Parse("2015/03/30 3:30:00", DateTimeFormatInfo.InvariantInfo).ToLocalTimeString() +
                           "</blockquote></a>";

            Assert.Equal(expected, TweetDetailsView.FormatQuoteTweetHtml(post, isReply: false));
        }
Ejemplo n.º 24
0
        public void ToUnixTime_Test()
        {
            var utc = new DateTimeUtc(2009, 2, 13, 23, 31, 30, 0);

            Assert.Equal(1234567890, utc.ToUnixTime());
        }
Ejemplo n.º 25
0
        public void ToString_FormatTest()
        {
            var utc = new DateTimeUtc(2018, 5, 6, 11, 22, 33, 111);

            Assert.Equal("2018-05-06 11:22:33.111 +00:00", utc.ToString("yyyy-MM-dd HH:mm:ss.fff zzz"));
        }
Ejemplo n.º 26
0
 public void Parse_ErrorTest()
 => Assert.Throws <FormatException>(() => DateTimeUtc.Parse("### INVALID ###", DateTimeFormatInfo.InvariantInfo));
Ejemplo n.º 27
0
 public void Parse_Test(string input, DateTimeUtc expected)
 => Assert.Equal(expected, DateTimeUtc.Parse(input, DateTimeFormatInfo.InvariantInfo));
Ejemplo n.º 28
0
 public void DateTimeParseTest(string date, DateTimeUtc excepted)
 => Assert.Equal(excepted, MyCommon.DateTimeParse(date));