public void GetEndOfDay()
        {
            TimeZoneInfo utc     = TimeZoneInfo.FindSystemTimeZoneById("UTC");
            TimeZoneInfo romance = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time");

            var samples = new[] {
                new GetOfDaySample("2019-03-18 23:59:59:999 +00:00", "2019-03-18 12:00:00:000 +00:00", null),
                new GetOfDaySample("2019-03-23 23:59:59:999 +00:00", "2019-03-23 12:00:00:000 +00:00", null),
                new GetOfDaySample("2019-03-26 23:59:59:999 +00:00", "2019-03-26 12:00:00:000 +00:00", null),

                new GetOfDaySample("2019-03-18 23:59:59:999 +00:00", "2019-03-18 12:00:00:000 +00:00", utc),
                new GetOfDaySample("2019-03-23 23:59:59:999 +00:00", "2019-03-23 12:00:00:000 +00:00", utc),
                new GetOfDaySample("2019-03-26 23:59:59:999 +00:00", "2019-03-26 12:00:00:000 +00:00", utc),

                new GetOfDaySample("2019-03-23 23:59:59:999 +01:00", "2019-03-23 12:00:00:000 +01:00", romance),
                new GetOfDaySample("2019-03-24 23:59:59:999 +01:00", "2019-03-24 12:00:00:000 +01:00", romance),

                new GetOfDaySample("2019-03-25 23:59:59:999 +01:00", "2019-03-25 12:00:00:000 +01:00", romance),
                new GetOfDaySample("2019-03-26 23:59:59:999 +01:00", "2019-03-26 12:00:00:000 +01:00", romance),
                new GetOfDaySample("2019-03-27 23:59:59:999 +01:00", "2019-03-27 12:00:00:000 +01:00", romance),
                new GetOfDaySample("2019-03-28 23:59:59:999 +01:00", "2019-03-28 12:00:00:000 +01:00", romance),
                new GetOfDaySample("2019-03-29 23:59:59:999 +01:00", "2019-03-29 12:00:00:000 +01:00", romance),
                new GetOfDaySample("2019-03-30 23:59:59:999 +01:00", "2019-03-30 12:00:00:000 +01:00", romance),
                new GetOfDaySample("2019-03-31 23:59:59:999 +02:00", "2019-03-31 12:00:00:000 +02:00", romance),

                new GetOfDaySample("2019-04-01 23:59:59:999 +02:00", "2019-04-01 12:00:00:000 +02:00", romance),
                new GetOfDaySample("2019-04-02 23:59:59:999 +02:00", "2019-04-02 12:00:00:000 +02:00", romance),

                new GetOfDaySample("2019-10-23 23:59:59:999 +02:00", "2019-10-23 12:00:00:000 +02:00", romance),
                new GetOfDaySample("2019-10-25 23:59:59:999 +02:00", "2019-10-25 12:00:00:000 +02:00", romance),
                new GetOfDaySample("2019-10-27 23:59:59:999 +01:00", "2019-10-27 12:00:00:000 +01:00", romance),
                new GetOfDaySample("2019-10-29 23:59:59:999 +01:00", "2019-10-29 12:00:00:000 +01:00", romance)
            };

            for (int i = 0; i < samples.Length; i++)
            {
                var s = samples[i];

                DateTimeOffset result1 = TimeUtils.GetEndOfDay(s.Time, s.TimeZone);

                EssentialsTime result2 = new EssentialsTime(s.Time, s.TimeZone).GetEndOfDay();

                EssentialsTime result3 = new EssentialsTime(s.Time, s.TimeZone).GetEndOfDay(s.TimeZone);

                Assert.AreEqual(s.Expected, result1.ToString(Format), $"Sample at index {i} failed test (DateTimeOffset)");

                Assert.AreEqual(s.Expected, result2.ToString(Format), $"Sample at index {i} failed test (EssentialsTime)");

                Assert.AreEqual(s.Expected, result2.ToString(Format), $"Sample at index {i} failed test (EssentialsTime)");
            }
        }
        public void ConstructorDateTimeAndTimeZoneInfo2()
        {
            TimeZoneInfo romance = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time");

            DateTime input = new DateTime(2020, 9, 27, 12, 17, 21, DateTimeKind.Utc);

            EssentialsTime result = new EssentialsTime(input, romance);

            Assert.AreEqual("2020-09-27 14:17:21:000 +02:00", result.ToString(Format));
        }
        public void ConstructorDateTimeAndTimeZoneInfo4()
        {
            // Notice: this test is likely fail if the local time zone isn't Romance Standard Time

            DateTime input = new DateTime(2020, 9, 27, 14, 17, 21, DateTimeKind.Local);

            EssentialsTime result = new EssentialsTime(input, TimeZoneInfo.Utc);

            Assert.AreEqual("2020-09-27 12:17:21:000 +00:00", result.ToString(Format));
        }
        public void ConstructorDateTimeAndTimeZoneInfo1()
        {
            TimeZoneInfo utc = TimeZoneInfo.FindSystemTimeZoneById("UTC");

            DateTime input = new DateTime(2020, 9, 27, 12, 17, 21, DateTimeKind.Utc);

            EssentialsTime result = new EssentialsTime(input, utc);

            Assert.AreEqual("2020-09-27 12:17:21:000 +00:00", result.ToString(Format));
        }
        public void ConstructorDateTimeAndTimeZoneInfo3()
        {
            // Convert to Eastern European Time
            TimeZoneInfo eet = TimeZoneInfo.FindSystemTimeZoneById("E. Europe Standard Time");

            DateTime input = new DateTime(2020, 9, 27, 12, 17, 21, DateTimeKind.Utc);

            EssentialsTime result = new EssentialsTime(input, eet);

            Assert.AreEqual("2020-09-27 15:17:21:000 +03:00", result.ToString(Format));
        }
        public void ToIso8601Milliseconds()
        {
            DateTimeOffset dto = new DateTimeOffset(2022, 3, 7, 17, 50, 23, 123, TimeSpan.FromHours(1));

            EssentialsTime time = new EssentialsTime(dto);

            using (new CultureDisposable(InvariantCulture)) {
                string actual1 = dto.ToString(Iso8601Constants.DateTimeMilliseconds, CultureInfo.InvariantCulture);
                string actual2 = time.ToString(Iso8601Constants.DateTimeMilliseconds);

                Assert.AreEqual("2022-03-07T17:50:23.123+01:00", actual1, "#1");
                Assert.AreEqual("2022-03-07T17:50:23.123+01:00", actual2, "#2");
            }

            using (new CultureDisposable(DanishCulture)) {
                string actual1 = dto.ToString(Iso8601Constants.DateTimeMilliseconds, CultureInfo.InvariantCulture);
                string actual2 = time.ToString(Iso8601Constants.DateTimeMilliseconds);

                Assert.AreEqual("2022-03-07T17:50:23.123+01:00", actual1, "#3");
                Assert.AreEqual("2022-03-07T17:50:23.123+01:00", actual2, "#4");
            }
        }
Beispiel #7
0
 /// <summary>
 /// Gets a list of time entries of the authenticated user.
 /// </summary>
 /// <param name="startDate">Only time entries after this date are returned.</param>
 /// <param name="endDate">Only time entries before this date are returned.</param>
 /// <returns>An instance of <see cref="IHttpResponse"/> representing the raw response.</returns>
 /// <see>
 ///     <cref>https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md#get-time-entries-started-in-a-specific-time-range</cref>
 /// </see>
 public IHttpResponse GetEntries(EssentialsTime startDate, EssentialsTime endDate)
 {
     if (startDate == null)
     {
         throw new ArgumentNullException(nameof(startDate));
     }
     if (endDate == null)
     {
         throw new ArgumentNullException(nameof(endDate));
     }
     return(Client.Get($"https://{TogglConstants.Track.HostName}/api/v8/time_entries", new HttpQueryString {
         { "start_date", startDate.ToString(Iso8601Constants.DateTimeFormat) },
         { "end_date", endDate.ToString(Iso8601Constants.DateTimeFormat) }
     }));
 }
        public void FromTicksLocal()
        {
            DateTime dt = new DateTime(2021, 1, 13, 22, 00, 00, DateTimeKind.Local);

            Assert.AreEqual(637461720000000000, dt.Ticks, "#1");

            // We can't use a format with offset or time zone, as it may differ depending on the environment
            Assert.AreEqual("2021-01-13T22:00:00", dt.ToString("yyyy-MM-ddTHH:mm:ss"), "#2");

            // Convert to EssentialsTime
            EssentialsTime time = EssentialsTime.FromTicks(dt.Ticks);

            Assert.AreEqual(637461720000000000, time.Ticks, "#3");
            Assert.AreEqual("2021-01-13T22:00:00", time.ToString("yyyy-MM-ddTHH:mm:ss"), "#4");
        }
        public void FromTicksLocalUtc()
        {
            DateTime dt = new DateTime(2021, 1, 13, 22, 00, 00, DateTimeKind.Utc);

            Assert.AreEqual(637461720000000000, dt.Ticks, "#1");

            // We can't use a format with offset or time zone, as it may differ depending on the environment
            Assert.AreEqual("2021-01-13T22:00:00Z", dt.ToString("yyyy-MM-ddTHH:mm:ssK"), "#2");

            // Convert to EssentialsTime
            EssentialsTime time = EssentialsTime.FromTicks(dt.Ticks, TimeSpan.Zero);

            // Same as DateTime
            Assert.AreEqual(637461720000000000, time.Ticks, "#3");

            // Offset is now +00:00 instead of Z (difference between DateTimeOffset and DateTime)
            Assert.AreEqual("2021-01-13T22:00:00+00:00", time.ToString("yyyy-MM-ddTHH:mm:ssK"), "#4");
        }
Beispiel #10
0
        public void FromIso8601Week()
        {
            TimeZoneInfo utc     = TimeZoneInfo.FindSystemTimeZoneById("UTC");
            TimeZoneInfo romance = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time");

            EssentialsTime time1 = EssentialsTime.FromIso8601Week(2019, 12, utc);
            EssentialsTime time2 = EssentialsTime.FromIso8601Week(2019, 13, utc);
            EssentialsTime time3 = EssentialsTime.FromIso8601Week(2019, 14, utc);

            EssentialsTime time4 = EssentialsTime.FromIso8601Week(2019, 12, romance);
            EssentialsTime time5 = EssentialsTime.FromIso8601Week(2019, 13, romance);
            EssentialsTime time6 = EssentialsTime.FromIso8601Week(2019, 14, romance);

            Assert.AreEqual("2019-03-18 00:00:00:000 +00:00", time1.ToString(Format), "#1");
            Assert.AreEqual("2019-03-25 00:00:00:000 +00:00", time2.ToString(Format), "#2");
            Assert.AreEqual("2019-04-01 00:00:00:000 +00:00", time3.ToString(Format), "#3");

            Assert.AreEqual("2019-03-18 00:00:00:000 +01:00", time4.ToString(Format), "#4");
            Assert.AreEqual("2019-03-25 00:00:00:000 +01:00", time5.ToString(Format), "#5");
            Assert.AreEqual("2019-04-01 00:00:00:000 +02:00", time6.ToString(Format), "#6");
        }