Пример #1
0
        Interval GetTodaysInterval(this IClock clock, DateTimeZone timeZone)
        {
            var today    = clock.GetCurrentInstant().InZone(timeZone).Date;
            var dayStart = timeZone.AtStartOfDay(today);
            var dayEnd   = timeZone.AtStartOfDay(today.PlusDays(1));

            return(new Interval(dayStart.ToInstant(), dayEnd.ToInstant()));
        }
Пример #2
0
        private static Interval GetDayIntervalForZone(Instant time, DateTimeZone timeZone)
        {
            var day      = time.InZone(timeZone).Date;
            var dayStart = timeZone.AtStartOfDay(day);
            var dayEnd   = timeZone.AtStartOfDay(day.PlusDays(1));

            return(new Interval(dayStart.ToInstant(), dayEnd.ToInstant()));
        }
        public void SkippedStartOfDay_TransitionAtMidnight()
        {
            // 1am because of the skip
            var expected = new ZonedDateTime(new LocalDateTime(2000, 6, 1, 1, 0), Offset.FromHours(-1),
                                             TransitionForwardAtMidnightZone);
            var actual = TransitionForwardAtMidnightZone.AtStartOfDay(TransitionDate);

            Assert.AreEqual(expected, actual);
        }
Пример #4
0
        public static Instant GetMonthEndInstant(this LocalDate forDate, DateTimeZone timeZone)
        {
            ZonedDateTime  zonedStartDateTime = timeZone.AtStartOfDay(forDate);
            CalendarSystem calendar           = zonedStartDateTime.Calendar;
            int            daysInMonth        = calendar.GetDaysInMonth(zonedStartDateTime.Year, zonedStartDateTime.Month);
            ZonedDateTime  zonedEndDateTime   =
                timeZone.AtStartOfDay(new LocalDate(zonedStartDateTime.Year, zonedStartDateTime.Month, daysInMonth));

            return(zonedEndDateTime.ToInstant());
        }
        /// <summary>
        /// Returns an <see cref="Interval"/> representing the local date in the given time zone.
        /// </summary>
        /// <param name="date">A local date.</param>
        /// <param name="timeZone">A time zone.</param>
        /// <returns></returns>
        public static Interval ToIntervalInZone(this LocalDate date, DateTimeZone timeZone)
        {
            var start = timeZone.AtStartOfDay(date);
            var end   = timeZone.AtEndOfDay(date);

            return(new Interval(start.ToInstant(), end.ToInstant()));
        }
        public void AtStartOfDay_DayDoesntExist(string zoneId, string localDate)
        {
            LocalDate    badDate   = LocalDatePattern.IsoPattern.Parse(localDate).Value;
            DateTimeZone zone      = DateTimeZoneProviders.Tzdb[zoneId];
            var          exception = Assert.Throws <SkippedTimeException>(() => zone.AtStartOfDay(badDate));

            Assert.AreEqual(badDate + LocalTime.Midnight, exception.LocalDateTime);
        }
Пример #7
0
        public IEnumerable <TimeInterval> SplitInto(TimePeriod period, DateTimeZone timezone)
        {
            EnsureArg.IsNotNull(timezone);

            var s = timezone.AtStartOfDay(_start);
            var n = timezone.AtStartOfDay(_start + GetIncrement());

            var c = new TimeInterval(s, period);
            var e = new TimeInterval(n, period);

            while (c < e)
            {
                yield return(c);

                c = c.NextInterval();
            }
        }
        public void AmbiguousStartOfDay_TransitionAfterMidnight()
        {
            // Occurrence before transition
            var expected = new ZonedDateTime(new LocalDateTime(2000, 6, 1, 0, 0), Offset.FromHours(-2),
                                             TransitionBackwardAfterMidnightZone);
            var actual = TransitionBackwardAfterMidnightZone.AtStartOfDay(TransitionDate);

            Assert.AreEqual(expected, actual);
        }
Пример #9
0
        public ScheduleView()
        {
            IClock       systemClock = SystemClock.Instance;
            Instant      now         = systemClock.GetCurrentInstant();
            DateTimeZone tz          = DateTimeZoneProviders.Tzdb.GetSystemDefault();
            LocalDate    today       = now.InZone(tz).Date;

            MonthViewStartDate = tz.AtStartOfDay(today).ToInstant();
        }
        public void SkippedStartOfDay_TransitionBeforeMidnight()
        {
            // 12.20am because of the skip
            var expected = new ZonedDateTime(new LocalDateTime(2000, 6, 1, 0, 20).WithOffset(Offset.FromHours(-1)),
                                             TransitionForwardBeforeMidnightZone);
            var actual = TransitionForwardBeforeMidnightZone.AtStartOfDay(TransitionDate);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(expected, TransitionDate.AtStartOfDayInZone(TransitionForwardBeforeMidnightZone));
        }
Пример #11
0
        public void Update(Size availableSize, Instant firstVisibleDay)
        {
            ColumnWidth = LayoutHelper.RoundLayoutValue(availableSize.Width / ColumnsCount);

            if (DoubleUtil.GreaterThanOrClose(ColumnWidth * ColumnsCount, availableSize.Width) == true)
            {
                ColumnWidth = LayoutHelper.FloorLayoutValue(availableSize.Width / ColumnsCount);
            }

            RowsHeight = LayoutHelper.RoundLayoutValue(availableSize.Height / RowsCount);

            if (DoubleUtil.GreaterThanOrClose(RowsHeight * RowsCount, availableSize.Height) == true)
            {
                RowsHeight = LayoutHelper.FloorLayoutValue(availableSize.Height / RowsCount);
            }

            GridCellSize = new Size(ColumnWidth, RowsHeight);

            Bounds = LayoutHelper.RoundLayoutRect3(new Rect(0, 0, ColumnWidth * ColumnsCount, RowsHeight * RowsCount));

            double columnOffset = 0;

            Grid = new MonthViewDay[RowsCount][];

            IClock       systemClock = SystemClock.Instance;
            Instant      now         = systemClock.GetCurrentInstant();
            DateTimeZone tz          = DateTimeZoneProviders.Tzdb.GetSystemDefault();
            LocalDate    today       = now.InZone(tz).Date;

            ZonedDateTime currentDay = tz.AtStartOfDay(today);

            for (int rowIndex = 0; rowIndex < RowsCount; rowIndex++)
            {
                columnOffset   = 0;
                Grid[rowIndex] = new MonthViewDay[ColumnsCount];

                for (int columnIndex = 0; columnIndex < ColumnsCount; columnIndex++)
                {
                    // ColumnWidth and RowHeight should be already layout rounded - so no need to round the rect bounds
                    var day = new MonthViewDay();
                    day.GridCell = new Rect(columnIndex * ColumnWidth, rowIndex * RowsHeight, ColumnWidth, RowsHeight);
                    var nextDay = currentDay.Plus(NodaTime.Duration.FromDays(1));
                    day.Day    = new Interval(currentDay.ToInstant(), nextDay.ToInstant()); // may be we should use 23:59:99999 as end interval?????
                    currentDay = nextDay;
                    Grid[rowIndex][columnIndex] = day;
                }

                columnOffset += ColumnWidth;
            }
        }
Пример #12
0
        public static int SettlementPeriod(this Instant instant)
        {
            var duration = instant - s_tzLondon.AtStartOfDay(instant.SettlementDate()).ToInstant();

            return((int)duration.TotalMinutes / 30 + 1);
        }
Пример #13
0
 /// <summary>
 /// Returns the earliest valid <see cref="ZonedDateTime"/> after the given local date.
 /// </summary>
 /// <remarks>
 /// If midnight exists unambiguously on the day after the given date, its midnight is returned.
 /// If the date has an ambiguous start time (e.g. the clocks go back from 1am to midnight) then
 /// the earlier <see cref="ZonedDateTime"/> is returned. If it has no midnight
 /// (e.g. the clocks go forward from midnight to 1am) then the earliest valid value is returned;
 /// this will be the instant of the transition.
 /// </remarks>
 /// <param name="timeZone">A time zone.</param>
 /// <param name="date">The local date to map in the given time zone.</param>
 /// <exception cref="SkippedTimeException">The entire day was skipped due to a very large time zone transition.
 /// (This is extremely rare.)</exception>
 /// <returns>The <see cref="ZonedDateTime"/> representing the earliest time in the given date, in this time zone.</returns>
 public static ZonedDateTime AtEndOfDay(this DateTimeZone timeZone, LocalDate date) => timeZone.AtStartOfDay(date.NextDay());
Пример #14
0
 public static Instant GetMonthStartInstant(this LocalDate localDate, DateTimeZone timeZone)
 {
     return(timeZone.AtStartOfDay(new LocalDate(localDate.Year, localDate.Month, 1)).ToInstant());
 }
Пример #15
0
 public static DateTime ToDateUtc(this DateTimeZone zone, LocalDate localDate)
 {
     //for requests
     return(zone.AtStartOfDay(localDate).ToDateTimeUtc().Date);
 }