示例#1
0
        public void ShouldGetLocalDateTimeForCurrentMonthSpanningDaylightSavingChange()
        {
            //Daylight saving finished on Sunday 1/4/2018 at 2am in NZ
            var localNowAfterChange = new LocalDateTime(2018, 4, 3, 15, 28, 10);//Tue 3/4/2018
            var start = localNowAfterChange.LocalDateTimeForDateRangeType(DateRangeType.CurrentMonth, true);
            var end   = localNowAfterChange.LocalDateTimeForDateRangeType(DateRangeType.CurrentMonth, false);

            Assert.Equal(new LocalDateTime(2018, 4, 1, 0, 0, 0), start);
            Assert.Equal(localNowAfterChange, end);
        }
示例#2
0
        public void ShouldGetLocalDateTimeForPriorToPreviousWeekSpanningDaylightSavingChange()
        {
            //Daylight saving finished on Sunday 1/4/2018 at 2am in NZ
            var localNowAfterChange = new LocalDateTime(2018, 4, 10, 15, 28, 10);//Tue 10/4/2018
            var start = localNowAfterChange.LocalDateTimeForDateRangeType(DateRangeType.PriorToPreviousWeek, true);
            var end   = localNowAfterChange.LocalDateTimeForDateRangeType(DateRangeType.PriorToPreviousWeek, false);

            Assert.Equal(new LocalDateTime(2018, 3, 26, 0, 0, 0), start);
            Assert.Equal(new LocalDateTime(2018, 4, 1, 23, 59, 59), end);
        }
示例#3
0
        /// <summary>
        /// Get the start or end date time in UTC for the specified date range type in the specified time zone.
        /// </summary>
        /// <param name="dateRangeType">The date range type (today, current week etc.)</param>
        /// <param name="ianaTimeZoneName">The IANA time zone name</param>
        /// <param name="isStart">True for start and false for end of date range</param>
        /// <param name="useEndOfCurrentDay">Flag to indicate if end of current periods are now or the end of the current day</param>
        /// <returns>The start or end UTC for the range in the time zone</returns>
        public static DateTime?UtcForDateRangeType(this DateRangeType dateRangeType, string ianaTimeZoneName, bool isStart, bool useEndOfCurrentDay = false)
        {
            if (dateRangeType == DateRangeType.Custom || dateRangeType == DateRangeType.ProjectExtents || string.IsNullOrEmpty(ianaTimeZoneName))
            {
                return(null);
            }

            DateTimeZone  timeZone = DateTimeZoneProviders.Tzdb[ianaTimeZoneName];
            ZonedClock    clock    = SystemClock.Instance.InZone(timeZone);
            LocalDateTime localNow = clock.GetCurrentLocalDateTime();
            var           local    = localNow.LocalDateTimeForDateRangeType(dateRangeType, isStart);
            var           zoned    = timeZone.AtLeniently(local);

            return(zoned.ToDateTimeUtc());
        }
示例#4
0
        public void ShouldGetLocalDateTimeForToday()
        {
            var start = localNow.LocalDateTimeForDateRangeType(DateRangeType.Today, true, true);
            var end   = localNow.LocalDateTimeForDateRangeType(DateRangeType.Today, false, true);

            Assert.Equal(startToday, start);
            Assert.Equal(endToday, end);
        }