Exemplo n.º 1
0
        /// <summary>
        /// Returns an <see cref="Instant"/> that represents the point in the given year that this
        /// object defines. If the exact point is not valid then the nearest point that matches the
        /// definition is returned.
        /// </summary>
        /// <param name="year">The year to calculate for.</param>
        /// <param name="standardOffset">The standard offset.</param>
        /// <param name="savings">The daylight savings adjustment.</param>
        /// <returns>The <see cref="Instant"/> of the point in the given year.</returns>
        internal Instant MakeInstant(int year, Offset standardOffset, Offset savings)
        {
            CalendarSystem calendar = CalendarSystem.Iso;

            if (year > calendar.MaxYear)
            {
                return(Instant.MaxValue);
            }
            if (year < calendar.MinYear)
            {
                return(Instant.MinValue);
            }
            LocalDate date = new LocalDate(year, monthOfYear, dayOfMonth > 0 ? dayOfMonth : 1);

            if (dayOfMonth < 0)
            {
                date = date.PlusMonths(1).PlusDays(dayOfMonth);
            }
            if (dayOfWeek != 0 && dayOfWeek != date.DayOfWeek)
            {
                IsoDayOfWeek isoDayOfWeek = (IsoDayOfWeek)dayOfWeek;
                date = advance ? date.Next(isoDayOfWeek) : date.Previous(isoDayOfWeek);
            }
            if (addDay)
            {
                date = date.PlusDays(1);
            }

            LocalInstant localInstant = (date + timeOfDay).LocalInstant;

            Offset offset = GetOffset(standardOffset, savings);

            // Convert from local time to UTC.
            return(localInstant.Minus(offset));
        }
Exemplo n.º 2
0
 public void MinusOffset_Zero_IsNeutralElement()
 {
     Instant sampleInstant = new Instant(1, 23456L);
     LocalInstant sampleLocalInstant = new LocalInstant(1, 23456L);
     Assert.AreEqual(sampleInstant, sampleLocalInstant.Minus(Offset.Zero));
     Assert.AreEqual(sampleInstant, sampleLocalInstant.MinusZeroOffset());
 }
Exemplo n.º 3
0
        public void MinusOffset_Zero_IsNeutralElement()
        {
            Instant      sampleInstant      = new Instant(1, 23456L);
            LocalInstant sampleLocalInstant = new LocalInstant(1, 23456L);

            Assert.AreEqual(sampleInstant, sampleLocalInstant.Minus(Offset.Zero));
            Assert.AreEqual(sampleInstant, sampleLocalInstant.MinusZeroOffset());
        }
        public void AtStrictly_InSummer()
        {
            var          when         = Pacific.AtStrictly(new LocalDateTime(2009, 6, 22, 21, 39, 30));
            Instant      instant      = when.ToInstant();
            LocalInstant localInstant = when.LocalInstant;

            Assert.AreEqual(instant, localInstant.Minus(Offset.FromHours(-7)));

            Assert.AreEqual(2009, when.Year);
            Assert.AreEqual(6, when.Month);
            Assert.AreEqual(22, when.Day);
            Assert.AreEqual(21, when.Hour);
            Assert.AreEqual(39, when.Minute);
            Assert.AreEqual(30, when.Second);
        }
Exemplo n.º 5
0
 private ZoneInterval GetIntervalAfterGap(LocalInstant localInstant)
 {
     Instant guess = new Instant(localInstant.Ticks);
     ZoneInterval guessInterval = GetZoneInterval(guess);
     // If the local interval occurs before the zone interval we're looking at starts,
     // it's the one we're looking for. Otherwise, we need to find the next interval.
     if (localInstant.Minus(guessInterval.Offset) < guessInterval.Start)
     {
         return guessInterval;
     }
     else
     {
         return GetZoneInterval(guessInterval.End);
     }
 }
Exemplo n.º 6
0
 private ZoneInterval GetIntervalBeforeGap(LocalInstant localInstant)
 {
     Instant guess = new Instant(localInstant.Ticks);
     ZoneInterval guessInterval = GetZoneInterval(guess);
     // If the local interval occurs before the zone interval we're looking at start,
     // we need to find the earlier one; otherwise this interval must come after the gap, and
     // it's therefore the one we want.
     if (localInstant.Minus(guessInterval.Offset) < guessInterval.Start)
     {
         return GetZoneInterval(guessInterval.Start - Duration.One);
     }
     else
     {
         return guessInterval;
     }
 }