public void PlusMonth_WithTruncation()
        {
            LocalDateTime start    = new LocalDateTime(2011, 1, 30, 12, 15, 8);
            LocalDateTime expected = new LocalDateTime(2011, 2, 28, 12, 15, 8);

            Assert.AreEqual(expected, start.PlusMonths(1));
        }
        public void PlusMonth_Simple()
        {
            LocalDateTime start    = new LocalDateTime(2012, 4, 15, 12, 15, 8);
            LocalDateTime expected = new LocalDateTime(2012, 8, 15, 12, 15, 8);

            Assert.AreEqual(expected, start.PlusMonths(4));
        }
        public void PlusMonth_ChangingYear()
        {
            LocalDateTime start    = new LocalDateTime(2012, 10, 15, 12, 15, 8);
            LocalDateTime expected = new LocalDateTime(2013, 2, 15, 12, 15, 8);

            Assert.AreEqual(expected, start.PlusMonths(4));
        }
Beispiel #4
0
        /// <summary>
        /// Get the start or end date time in a time zone for the specified date range type.
        /// </summary>
        /// <param name="nowInTimeZone">Now in time zone</param>
        /// <param name="dateRangeType">The date range type (today, current week etc.)</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 date time for the range in the time zone</returns>
        public static LocalDateTime LocalDateTimeForDateRangeType(this LocalDateTime nowInTimeZone, DateRangeType dateRangeType, bool isStart, bool useEndOfCurrentDay = false)
        {
            LocalDateTime startToday = nowInTimeZone.PlusTicks(-nowInTimeZone.TickOfDay);
            LocalDateTime endToday   = startToday.PlusDays(1).PlusSeconds(-1);
            var           currentEnd = useEndOfCurrentDay ? endToday : nowInTimeZone;

            var startThisWeek  = startToday.With(DateAdjusters.PreviousOrSame(IsoDayOfWeek.Monday));
            var startThisMonth = startToday.With(DateAdjusters.StartOfMonth);

            LocalDateTime dateTimeInTimeZone = nowInTimeZone;

            switch (dateRangeType)
            {
            case DateRangeType.Today:
                dateTimeInTimeZone = isStart ? startToday : currentEnd;
                break;

            case DateRangeType.Yesterday:
            case DateRangeType.PriorToYesterday:
                dateTimeInTimeZone = isStart ? startToday.PlusDays(-1) : startToday.PlusSeconds(-1);
                if (dateRangeType == DateRangeType.PriorToYesterday)
                {
                    dateTimeInTimeZone = dateTimeInTimeZone.PlusDays(-1);
                }
                break;

            case DateRangeType.CurrentWeek:
                dateTimeInTimeZone = isStart ? startThisWeek : currentEnd;
                break;

            case DateRangeType.PreviousWeek:
            case DateRangeType.PriorToPreviousWeek:
                dateTimeInTimeZone = isStart ? startThisWeek.PlusDays(-7) : startThisWeek.PlusSeconds(-1);
                if (dateRangeType == DateRangeType.PriorToPreviousWeek)
                {
                    dateTimeInTimeZone = dateTimeInTimeZone.PlusDays(-7);
                }
                break;

            case DateRangeType.CurrentMonth:
                dateTimeInTimeZone = isStart ? startThisMonth : currentEnd;
                break;

            case DateRangeType.PreviousMonth:
            case DateRangeType.PriorToPreviousMonth:
                dateTimeInTimeZone = isStart ? startThisMonth.PlusMonths(-1) : startThisMonth.PlusSeconds(-1);
                if (dateRangeType == DateRangeType.PriorToPreviousMonth)
                {
                    dateTimeInTimeZone = dateTimeInTimeZone.PlusMonths(-1);
                }
                break;

            case DateRangeType.ProjectExtents:
            case DateRangeType.Custom:
                //do nothing
                break;
            }
            return(dateTimeInTimeZone);
        }
 public static LocalDateTime WithMonthOfYear(this LocalDateTime instance, int month)
 {
     if (month < 1 || month > 12)
     {
         throw new ArgumentException(nameof(month));
     }
     return(instance.PlusMonths(month - instance.Month));
 }
Beispiel #6
0
        public void ShouldGetLocalDateTimeForPriorToPreviousMonth()
        {
            var start = localNow.LocalDateTimeForDateRangeType(DateRangeType.PriorToPreviousMonth, true, true);
            var end   = localNow.LocalDateTimeForDateRangeType(DateRangeType.PriorToPreviousMonth, false, true);

            Assert.Equal(startPreviousMonth.PlusMonths(-1), start);
            Assert.Equal(endPreviousMonth.PlusMonths(-1), end);
        }
Beispiel #7
0
        public void DateNotInPeriodThrows(LocalDateTime value)
        {
            var period = AccountingPeriod.Open(value.Date);
            var ex     = Assert.Throws <ClosingDateBeforePeriodException>(() =>
                                                                          period.MustNotBeAfter(value.PlusMonths(-1).Date));

            Assert.Equal(value.PlusMonths(-1).Date, ex.Date);
            Assert.Equal(period, ex.AccountingPeriod);
        }
        public LocalDateTime?ComputeNextExecutionTime(LocalDateTime lastExecutionTime)
        {
            var currentMonthExecutionTime = new LocalDateTime(lastExecutionTime.Year, lastExecutionTime.Month, this._dayOfMonth, this._hourOfDay, this._minuteOfHour);

            if (lastExecutionTime < currentMonthExecutionTime)
            {
                return(currentMonthExecutionTime);
            }

            return(currentMonthExecutionTime.PlusMonths(1));
        }
        public void PlusMonths_Simple()
        {
            var calendar = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.Base15, IslamicEpoch.Civil);

            Assert.IsTrue(calendar.IsLeapYear(2));

            LocalDateTime start       = new LocalDateTime(2, 12, 30, 2, 0, calendar);
            LocalDateTime expectedEnd = new LocalDateTime(3, 11, 30, 2, 0, calendar);

            Assert.AreEqual(11, expectedEnd.Month);
            Assert.AreEqual(30, expectedEnd.Day);
            Assert.AreEqual(expectedEnd, start.PlusMonths(11));
        }
 public void PlusMonths()
 {
     Sample.PlusMonths(3).Consume();
 }
Beispiel #11
0
 public IDateTime PlusMinutes(int minutes)
 {
     return(new DateTime(_localDateTime.PlusMonths(minutes)));
 }
Beispiel #12
0
 public LocalDateTime PlusMonths() => Sample.PlusMonths(3);
        public void PlusMonths_Simple()
        {
            var calendar = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.Base15, IslamicEpoch.Civil);
            Assert.IsTrue(calendar.IsLeapYear(2));

            LocalDateTime start = new LocalDateTime(2, 12, 30, 2, 0, calendar);
            LocalDateTime expectedEnd = new LocalDateTime(3, 11, 30, 2, 0, calendar);
            Assert.AreEqual(11, expectedEnd.Month);
            Assert.AreEqual(30, expectedEnd.Day);
            Assert.AreEqual(expectedEnd, start.PlusMonths(11));
        }
 /// <summary>
 /// Add quarters
 /// </summary>
 /// <param name="ld"></param>
 /// <param name="quarters"></param>
 /// <returns></returns>
 public static LocalDateTime AddQuarters(this LocalDateTime ld, int quarters) => ld.PlusMonths(quarters * 3);
 public void PlusMonth_WithTruncation()
 {
     LocalDateTime start = new LocalDateTime(2011, 1, 30, 12, 15, 8);
     LocalDateTime expected = new LocalDateTime(2011, 2, 28, 12, 15, 8);
     Assert.AreEqual(expected, start.PlusMonths(1));
 }
 public void PlusMonth_ChangingYear()
 {
     LocalDateTime start = new LocalDateTime(2012, 10, 15, 12, 15, 8);
     LocalDateTime expected = new LocalDateTime(2013, 2, 15, 12, 15, 8);
     Assert.AreEqual(expected, start.PlusMonths(4));
 }
 public void PlusMonth_Simple()
 {
     LocalDateTime start = new LocalDateTime(2012, 4, 15, 12, 15, 8);
     LocalDateTime expected = new LocalDateTime(2012, 8, 15, 12, 15, 8);
     Assert.AreEqual(expected, start.PlusMonths(4));
 }
 public LocalDateTime PlusMonths()
 {
     return(Sample.PlusMonths(3));
 }
Beispiel #19
0
 public void PlusMonths()
 {
     SampleStartDateTime.PlusMonths(3);
 }
 /// <summary>
 /// Add months
 /// </summary>
 /// <param name="ld"></param>
 /// <param name="months"></param>
 /// <returns></returns>
 public static LocalDateTime AddMonths(this LocalDateTime ld, int months) => ld.PlusMonths(months);