SetToMax() public method

public SetToMax ( ) : void
return void
Example #1
0
        /// <summary>
        /// Coerces the <paramref name="utcDateTime"/> according to the min and max
        /// allowed values of the <paramref name="calendar"/> parameter.
        /// </summary>
        /// <returns>The coerced value.</returns>
        internal static DateTime CoerceDateTime(DateTime utcDateTime, Windows.Globalization.Calendar calendar)
        {
            var calendarValue = calendar.GetDateTime().UtcDateTime;
            var dateTime      = DateTime.SpecifyKind(utcDateTime, DateTimeKind.Utc);

            calendar.SetToMin();
            calendar.AddDays(1);
            var minValue = calendar.GetDateTime().UtcDateTime.AddDays(-1);

            calendar.SetToMax();
            calendar.AddDays(-1);
            var maxValue = calendar.GetDateTime().UtcDateTime.AddDays(1);

            calendar.SetDateTime(calendarValue);

            if (dateTime < minValue)
            {
                return(DateTime.SpecifyKind(minValue, utcDateTime.Kind));
            }

            if (dateTime > maxValue)
            {
                return(DateTime.SpecifyKind(maxValue, utcDateTime.Kind));
            }

            return(utcDateTime);
        }
Example #2
0
        public void TestCalendarLimits(string calendar)
        {
            using var _ = new AssertionScope();

            var sut = new WG.Calendar(new [] { "en" }, WG.CalendarIdentifiers.Japanese, "24HourClock");

            sut.SetToMin();
            CheckLimits($"Min");

            sut.SetToMax();
            CheckLimits($"Max");

            sut.SetToNow();
            CheckLimits($"Max");

            void CheckLimits(string context)
            {
                // Following tests are just to ensure no exceptions are raised
                // by asking those values
                sut.NumberOfEras.Should().BePositive(context);
                sut.Era.Should().BePositive(context);
                sut.FirstMonthInThisYear.Should().BePositive(context);
                sut.NumberOfDaysInThisMonth.Should().BePositive(context);
                sut.DayOfWeek.Should().NotBeNull(context);
                sut.NumberOfEras.Should().BePositive(context);
                sut.FirstEra.Should().BePositive(context);
                sut.LastEra.Should().BePositive(context);
                sut.Period.Should().BePositive(context);
                sut.ResolvedLanguage.Should().NotBeEmpty(context);
            }
        }