Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCompareDerivedValue()
        internal virtual void ShouldCompareDerivedValue()
        {
            TimeValue value1 = time(4242, ZoneOffset.of("-12:00"));
            TimeValue value2 = time(value1.Temporal());

            assertEquals(0, value1.UnsafeCompareTo(value2));
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="standardTransitions">  the standard transitions, not null </param>
        /// <param name="standardOffsets">  the standard offsets, not null </param>
        /// <param name="savingsInstantTransitions">  the standard transitions, not null </param>
        /// <param name="wallOffsets">  the wall offsets, not null </param>
        /// <param name="lastRules">  the recurring last rules, size 15 or less, not null </param>
        private ZoneRules(long[] standardTransitions, ZoneOffset[] standardOffsets, long[] savingsInstantTransitions, ZoneOffset[] wallOffsets, ZoneOffsetTransitionRule[] lastRules) : base()
        {
            this.StandardTransitions       = standardTransitions;
            this.StandardOffsets           = standardOffsets;
            this.SavingsInstantTransitions = savingsInstantTransitions;
            this.WallOffsets = wallOffsets;
            this.LastRules   = lastRules;

            if (savingsInstantTransitions.Length == 0)
            {
                this.SavingsLocalTransitions = EMPTY_LDT_ARRAY;
            }
            else
            {
                // convert savings transitions to locals
                IList <LocalDateTime> localTransitionList = new List <LocalDateTime>();
                for (int i = 0; i < savingsInstantTransitions.Length; i++)
                {
                    ZoneOffset           before = wallOffsets[i];
                    ZoneOffset           after  = wallOffsets[i + 1];
                    ZoneOffsetTransition trans  = new ZoneOffsetTransition(savingsInstantTransitions[i], before, after);
                    if (trans.Gap)
                    {
                        localTransitionList.Add(trans.DateTimeBefore);
                        localTransitionList.Add(trans.DateTimeAfter);
                    }
                    else
                    {
                        localTransitionList.Add(trans.DateTimeAfter);
                        localTransitionList.Add(trans.DateTimeBefore);
                    }
                }
                this.SavingsLocalTransitions = localTransitionList.ToArray();
            }
        }
Esempio n. 3
0
        public static OffsetTime TruncateOffsetToMinutes(OffsetTime value)
        {
            int        offsetMinutes   = value.Offset.TotalSeconds / 60;
            ZoneOffset truncatedOffset = ZoneOffset.ofTotalSeconds(offsetMinutes * 60);

            return(value.withOffsetSameInstant(truncatedOffset));
        }
Esempio n. 4
0
        /// <summary>
        /// Reads the state from the stream.
        /// </summary>
        /// <param name="in">  the input stream, not null </param>
        /// <returns> the created object, not null </returns>
        /// <exception cref="IOException"> if an error occurs </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static ZoneRules readExternal(java.io.DataInput in) throws java.io.IOException, ClassNotFoundException
        internal static ZoneRules ReadExternal(DataInput @in)
        {
            int stdSize = @in.ReadInt();

            long[] stdTrans = (stdSize == 0) ? EMPTY_LONG_ARRAY : new long[stdSize];
            for (int i = 0; i < stdSize; i++)
            {
                stdTrans[i] = Ser.ReadEpochSec(@in);
            }
            ZoneOffset[] stdOffsets = new ZoneOffset[stdSize + 1];
            for (int i = 0; i < stdOffsets.Length; i++)
            {
                stdOffsets[i] = Ser.ReadOffset(@in);
            }
            int savSize = @in.ReadInt();

            long[] savTrans = (savSize == 0) ? EMPTY_LONG_ARRAY : new long[savSize];
            for (int i = 0; i < savSize; i++)
            {
                savTrans[i] = Ser.ReadEpochSec(@in);
            }
            ZoneOffset[] savOffsets = new ZoneOffset[savSize + 1];
            for (int i = 0; i < savOffsets.Length; i++)
            {
                savOffsets[i] = Ser.ReadOffset(@in);
            }
            int ruleSize = @in.ReadByte();

            ZoneOffsetTransitionRule[] rules = (ruleSize == 0) ? EMPTY_LASTRULES : new ZoneOffsetTransitionRule[ruleSize];
            for (int i = 0; i < ruleSize; i++)
            {
                rules[i] = ZoneOffsetTransitionRule.ReadExternal(@in);
            }
            return(new ZoneRules(stdTrans, stdOffsets, savTrans, savOffsets, rules));
        }
Esempio n. 5
0
        public static TimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            OffsetTime time        = input.getTimePart(defaultZone);
            OffsetTime truncatedOT = AssertValidUnit(() => time.truncatedTo(unit));

            if (fields.Size() == 0)
            {
                return(time(truncatedOT));
            }
            else
            {
                // Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time
                AnyValue timezone = fields.Get("timezone");
                if (timezone != NO_VALUE)
                {
                    ZonedDateTime currentDT     = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.now(), TimezoneOf(timezone)));
                    ZoneOffset    currentOffset = currentDT.Offset;
                    truncatedOT = truncatedOT.withOffsetSameLocal(currentOffset);
                }

                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedOT, (mapValue, offsetTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return time(offsetTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("time", time(offsetTime)), defaultZone);
                    }
                }));
            }
        }
Esempio n. 6
0
        internal override OffsetTime GetTimePart(System.Func <ZoneId> defaultZone)
        {
            ZoneOffset offset    = _value.Offset;
            LocalTime  localTime = _value.toLocalTime();

            return(OffsetTime.of(localTime, offset));
        }
Esempio n. 7
0
        private int FindYear(long epochSecond, ZoneOffset offset)
        {
            // inline for performance
            long localSecond   = epochSecond + offset.TotalSeconds;
            long localEpochDay = Math.FloorDiv(localSecond, 86400);

            return(LocalDate.OfEpochDay(localEpochDay).Year);
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldTruncateOffsetSeconds()
        internal virtual void ShouldTruncateOffsetSeconds()
        {
            OffsetTime time = OffsetTime.of(14, 55, 50, 0, ZoneOffset.ofHoursMinutesSeconds(2, 15, 45));

            OffsetTime truncatedTime = TemporalUtil.TruncateOffsetToMinutes(time);

            assertEquals(OffsetTime.of(14, 55, 5, 0, ZoneOffset.ofHoursMinutes(2, 15)), truncatedTime);
        }
Esempio n. 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldDoNothingForOffsetWithoutSeconds()
        internal virtual void ShouldDoNothingForOffsetWithoutSeconds()
        {
            OffsetTime time = OffsetTime.of(23, 30, 10, 0, ZoneOffset.ofHoursMinutes(-5, -30));

            OffsetTime truncatedTime = TemporalUtil.TruncateOffsetToMinutes(time);

            assertEquals(time, truncatedTime);
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.values.storable.DateTimeValue unpackDateTimeWithZoneOffset() throws java.io.IOException
            internal virtual DateTimeValue UnpackDateTimeWithZoneOffset()
            {
                long epochSecondLocal = UnpackLong();
                long nano             = UnpackLong();
                int  offsetSeconds    = UnpackInteger();

                return(datetime(NewZonedDateTime(epochSecondLocal, nano, ZoneOffset.ofTotalSeconds(offsetSeconds))));
            }
Esempio n. 11
0
 /// <summary>
 /// Obtains an instance of a ZoneRules.
 /// </summary>
 /// <param name="baseStandardOffset">  the standard offset to use before legal rules were set, not null </param>
 /// <param name="baseWallOffset">  the wall offset to use before legal rules were set, not null </param>
 /// <param name="standardOffsetTransitionList">  the list of changes to the standard offset, not null </param>
 /// <param name="transitionList">  the list of transitions, not null </param>
 /// <param name="lastRules">  the recurring last rules, size 16 or less, not null </param>
 /// <returns> the zone rules, not null </returns>
 public static ZoneRules Of(ZoneOffset baseStandardOffset, ZoneOffset baseWallOffset, IList <ZoneOffsetTransition> standardOffsetTransitionList, IList <ZoneOffsetTransition> transitionList, IList <ZoneOffsetTransitionRule> lastRules)
 {
     Objects.RequireNonNull(baseStandardOffset, "baseStandardOffset");
     Objects.RequireNonNull(baseWallOffset, "baseWallOffset");
     Objects.RequireNonNull(standardOffsetTransitionList, "standardOffsetTransitionList");
     Objects.RequireNonNull(transitionList, "transitionList");
     Objects.RequireNonNull(lastRules, "lastRules");
     return(new ZoneRules(baseStandardOffset, baseWallOffset, standardOffsetTransitionList, transitionList, lastRules));
 }
Esempio n. 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleDateTimeWithTimeZoneOffset()
        internal virtual void ShouldHandleDateTimeWithTimeZoneOffset()
        {
            DateTimeValue datetime = datetime(1988, 4, 19, 10, 12, 59, 112233445, ZoneOffset.ofHoursMinutes(3, 15));
            PrettyPrinter printer  = new PrettyPrinter();

            datetime.WriteTo(printer);

            assertEquals("{datetime: \"1988-04-19T10:12:59.112233445+03:15\"}", printer.Value());
        }
Esempio n. 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleTime()
        internal virtual void ShouldHandleTime()
        {
            TimeValue     time    = time(11, 19, 11, 123456789, ZoneOffset.ofHoursMinutes(-9, -30));
            PrettyPrinter printer = new PrettyPrinter();

            time.WriteTo(printer);

            assertEquals("{time: \"11:19:11.123456789-09:30\"}", printer.Value());
        }
Esempio n. 14
0
 internal static OffsetTime AsValueRaw(long long0, long long1)
 {
     if (TimeZones.validZoneOffset(( int )long1))
     {
         return(TimeValue.timeRaw(long0, ZoneOffset.ofTotalSeconds(( int )long1)));
     }
     // TODO Getting here means that after a proper read this value is plain wrong... shouldn't something be thrown instead? Yes and same for TimeZones
     return(null);
 }
Esempio n. 15
0
 public override Value AsValue()
 {
     // We need to check validity upfront without throwing exceptions, because the PageCursor might give garbage bytes
     if (TimeZones.validZoneOffset(ZoneOffsetSeconds))
     {
         return(TimeValue.time(NanosOfDayUTC, ZoneOffset.ofTotalSeconds(ZoneOffsetSeconds)));
     }
     return(NO_VALUE);
 }
Esempio n. 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldWriteDerivedValueThatIsEqual()
        internal virtual void ShouldWriteDerivedValueThatIsEqual()
        {
            TimeValue value1 = time(42, ZoneOffset.of("-18:00"));
            TimeValue value2 = time(value1.Temporal());

            OffsetTime offsetTime1 = Write(value1);
            OffsetTime offsetTime2 = Write(value2);

            assertEquals(offsetTime1, offsetTime2);
        }
Esempio n. 17
0
 /// <summary>
 /// Creates an instance of ZoneRules that has fixed zone rules.
 /// </summary>
 /// <param name="offset">  the offset this fixed zone rules is based on, not null </param>
 /// <returns> the zone rules, not null </returns>
 /// <seealso cref= #isFixedOffset() </seealso>
 private ZoneRules(ZoneOffset offset)
 {
     this.StandardOffsets           = new ZoneOffset[1];
     this.StandardOffsets[0]        = offset;
     this.StandardTransitions       = EMPTY_LONG_ARRAY;
     this.SavingsInstantTransitions = EMPTY_LONG_ARRAY;
     this.SavingsLocalTransitions   = EMPTY_LDT_ARRAY;
     this.WallOffsets = StandardOffsets;
     this.LastRules   = EMPTY_LASTRULES;
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static ChronoZonedDateTime<?> readExternal(java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
		internal static ChronoZonedDateTime<?> ReadExternal(ObjectInput @in)
		{
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: ChronoLocalDateTime<?> dateTime = (ChronoLocalDateTime<?>) in.readObject();
			ChronoLocalDateTime<?> dateTime = (ChronoLocalDateTime<?>) @in.ReadObject();
			ZoneOffset offset = (ZoneOffset) @in.ReadObject();
			ZoneId zone = (ZoneId) @in.ReadObject();
			return dateTime.AtZone(offset).WithZoneSameLocal(zone);
			// TODO: ZDT uses ofLenient()
		}
Esempio n. 19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void checkLogRecordTimeZone(ConsistencyCheckService service, String[] args, int hoursShift, String timeZoneSuffix) throws org.neo4j.consistency.ConsistencyCheckTool.ToolFailureException, java.io.IOException
        private static void CheckLogRecordTimeZone(ConsistencyCheckService service, string[] args, int hoursShift, string timeZoneSuffix)
        {
            TimeZone.Default = TimeZone.getTimeZone(ZoneOffset.ofHours(hoursShift));
            MemoryStream outputStream = new MemoryStream();
            PrintStream  printStream  = new PrintStream(outputStream);

            RunConsistencyCheckToolWith(service, printStream, args);
            string logLine = ReadLogLine(outputStream);

            assertTrue(logLine, logLine.Contains(timeZoneSuffix));
        }
Esempio n. 20
0
        private static ZoneOffset ParseOffset(Matcher matcher, System.Func <ZoneId> defaultZone)
        {
            ZoneOffset offset = ParseOffset(matcher);

            if (offset == null)
            {
                ZoneId zoneId = defaultZone();
                offset = zoneId is ZoneOffset ? ( ZoneOffset )zoneId : zoneId.Rules.getOffset(Instant.now());
            }
            return(offset);
        }
		/// <summary>
		/// Obtains an instance from an instant using the specified time-zone.
		/// </summary>
		/// <param name="chrono">  the chronology, not null </param>
		/// <param name="instant">  the instant, not null </param>
		/// <param name="zone">  the zone identifier, not null </param>
		/// <returns> the zoned date-time, not null </returns>
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: static ChronoZonedDateTimeImpl<?> ofInstant(Chronology ChronoZonedDateTime_Fields.chrono, java.time.Instant instant, java.time.ZoneId zone)
		internal static ChronoZonedDateTimeImpl<?> OfInstant(Chronology ChronoZonedDateTime_Fields, Instant instant, ZoneId zone)
		{
			ZoneRules rules = zone.Rules;
			ZoneOffset offset = rules.GetOffset(instant);
			Objects.RequireNonNull(offset, "offset"); // protect against bad ZoneRules
			LocalDateTime ldt = LocalDateTime.OfEpochSecond(instant.EpochSecond, instant.Nano, offset);
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: ChronoLocalDateTimeImpl<?> cldt = (ChronoLocalDateTimeImpl<?>)ChronoZonedDateTime_Fields.chrono.localDateTime(ldt);
			ChronoLocalDateTimeImpl<?> cldt = (ChronoLocalDateTimeImpl<?>)ChronoZonedDateTime_Fields.Chrono.localDateTime(ldt);
			return new ChronoZonedDateTimeImpl<>(cldt, offset, zone);
		}
Esempio n. 22
0
        /// <summary>
        /// Gets the amount of daylight savings in use for the specified instant in this zone.
        /// <para>
        /// This provides access to historic information on how the amount of daylight
        /// savings has changed over time.
        /// This is the difference between the standard offset and the actual offset.
        /// Typically the amount is zero during winter and one hour during summer.
        /// Time-zones are second-based, so the nanosecond part of the duration will be zero.
        /// </para>
        /// <para>
        /// This default implementation calculates the duration from the
        /// <seealso cref="#getOffset(java.time.Instant) actual"/> and
        /// <seealso cref="#getStandardOffset(java.time.Instant) standard"/> offsets.
        ///
        /// </para>
        /// </summary>
        /// <param name="instant">  the instant to find the daylight savings for, not null, but null
        ///  may be ignored if the rules have a single offset for all instants </param>
        /// <returns> the difference between the standard and actual offset, not null </returns>
        public Duration GetDaylightSavings(Instant instant)
        {
            if (SavingsInstantTransitions.Length == 0)
            {
                return(Duration.ZERO);
            }
            ZoneOffset standardOffset = GetStandardOffset(instant);
            ZoneOffset actualOffset   = GetOffset(instant);

            return(Duration.OfSeconds(actualOffset.TotalSeconds - standardOffset.TotalSeconds));
        }
        /// <summary>
        /// Reads the state from the stream.
        /// </summary>
        /// <param name="in">  the input stream, not null </param>
        /// <returns> the created object, not null </returns>
        /// <exception cref="IOException"> if an error occurs </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static ZoneOffsetTransition readExternal(java.io.DataInput in) throws java.io.IOException
        internal static ZoneOffsetTransition ReadExternal(DataInput @in)
        {
            long       epochSecond = Ser.ReadEpochSec(@in);
            ZoneOffset before      = Ser.ReadOffset(@in);
            ZoneOffset after       = Ser.ReadOffset(@in);

            if (before.Equals(after))
            {
                throw new IllegalArgumentException("Offsets must not be equal");
            }
            return(new ZoneOffsetTransition(epochSecond, before, after));
        }
Esempio n. 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldGetNanosOfDayUTC()
        internal virtual void ShouldGetNanosOfDayUTC()
        {
            LocalTime  localTime = LocalTime.of(14, 19, 18, 123999);
            ZoneOffset offset    = ZoneOffset.ofHours(-12);
            OffsetTime time      = OffsetTime.of(localTime, offset);

            long nanosOfDayUTC = TemporalUtil.GetNanosOfDayUTC(time);

            long expectedNanosOfDayUTC = Duration.ofSeconds(localTime.toSecondOfDay()).minus(offset.TotalSeconds, SECONDS).toNanos();

            assertEquals(expectedNanosOfDayUTC + localTime.Nano, nanosOfDayUTC);
        }
Esempio n. 25
0
 /// <summary>
 /// Creates an instance defining the yearly rule to create transitions between two offsets.
 /// </summary>
 /// <param name="month">  the month of the month-day of the first day of the cutover week, not null </param>
 /// <param name="dayOfMonthIndicator">  the day of the month-day of the cutover week, positive if the week is that
 ///  day or later, negative if the week is that day or earlier, counting from the last day of the month,
 ///  from -28 to 31 excluding 0 </param>
 /// <param name="dayOfWeek">  the required day-of-week, null if the month-day should not be changed </param>
 /// <param name="time">  the cutover time in the 'before' offset, not null </param>
 /// <param name="timeEndOfDay">  whether the time is midnight at the end of day </param>
 /// <param name="timeDefnition">  how to interpret the cutover </param>
 /// <param name="standardOffset">  the standard offset in force at the cutover, not null </param>
 /// <param name="offsetBefore">  the offset before the cutover, not null </param>
 /// <param name="offsetAfter">  the offset after the cutover, not null </param>
 /// <exception cref="IllegalArgumentException"> if the day of month indicator is invalid </exception>
 /// <exception cref="IllegalArgumentException"> if the end of day flag is true when the time is not midnight </exception>
 internal ZoneOffsetTransitionRule(Month month, int dayOfMonthIndicator, DayOfWeek dayOfWeek, LocalTime time, bool timeEndOfDay, TimeDefinition timeDefnition, ZoneOffset standardOffset, ZoneOffset offsetBefore, ZoneOffset offsetAfter)
 {
     this.Month_Renamed          = month;
     this.Dom                    = (sbyte)dayOfMonthIndicator;
     this.Dow                    = dayOfWeek;
     this.Time                   = time;
     this.TimeEndOfDay           = timeEndOfDay;
     this.TimeDefinition_Renamed = timeDefnition;
     this.StandardOffset_Renamed = standardOffset;
     this.OffsetBefore_Renamed   = offsetBefore;
     this.OffsetAfter_Renamed    = offsetAfter;
 }
Esempio n. 26
0
        /// <summary>
        /// Gets the previous transition before the specified instant.
        /// <para>
        /// This returns details of the previous transition after the specified instant.
        /// For example, if the instant represents a point where "summer" daylight saving time
        /// applies, then the method will return the transition from the previous "winter" time.
        ///
        /// </para>
        /// </summary>
        /// <param name="instant">  the instant to get the previous transition after, not null, but null
        ///  may be ignored if the rules have a single offset for all instants </param>
        /// <returns> the previous transition after the specified instant, null if this is before the first transition </returns>
        public ZoneOffsetTransition PreviousTransition(Instant instant)
        {
            if (SavingsInstantTransitions.Length == 0)
            {
                return(null);
            }
            long epochSec = instant.EpochSecond;

            if (instant.Nano > 0 && epochSec < Long.MaxValue)
            {
                epochSec += 1;                 // allow rest of method to only use seconds
            }

            // check if using last rules
            long lastHistoric = SavingsInstantTransitions[SavingsInstantTransitions.Length - 1];

            if (LastRules.Length > 0 && epochSec > lastHistoric)
            {
                // search year the instant is in
                ZoneOffset             lastHistoricOffset = WallOffsets[WallOffsets.Length - 1];
                int                    year       = FindYear(epochSec, lastHistoricOffset);
                ZoneOffsetTransition[] transArray = FindTransitionArray(year);
                for (int i = transArray.Length - 1; i >= 0; i--)
                {
                    if (epochSec > transArray[i].ToEpochSecond())
                    {
                        return(transArray[i]);
                    }
                }
                // use last from preceding year
                int lastHistoricYear = FindYear(lastHistoric, lastHistoricOffset);
                if (--year > lastHistoricYear)
                {
                    transArray = FindTransitionArray(year);
                    return(transArray[transArray.Length - 1]);
                }
                // drop through
            }

            // using historic rules
            int index = Arrays.BinarySearch(SavingsInstantTransitions, epochSec);

            if (index < 0)
            {
                index = -index - 1;
            }
            if (index <= 0)
            {
                return(null);
            }
            return(new ZoneOffsetTransition(SavingsInstantTransitions[index - 1], WallOffsets[index - 1], WallOffsets[index]));
        }
		public override ChronoZonedDateTime<D> WithLaterOffsetAtOverlap()
		{
			ZoneOffsetTransition trans = Zone.Rules.GetTransition(LocalDateTime.From(this));
			if (trans != null)
			{
				ZoneOffset offset = trans.OffsetAfter;
				if (offset.Equals(Offset) == false)
				{
					return new ChronoZonedDateTimeImpl<>(DateTime, offset, Zone_Renamed);
				}
			}
			return this;
		}
		public override ChronoZonedDateTime<D> WithEarlierOffsetAtOverlap()
		{
			ZoneOffsetTransition trans = Zone.Rules.GetTransition(LocalDateTime.From(this));
			if (trans != null && trans.Overlap)
			{
				ZoneOffset earlierOffset = trans.OffsetBefore;
				if (earlierOffset.Equals(Offset_Renamed) == false)
				{
					return new ChronoZonedDateTimeImpl<>(DateTime, earlierOffset, Zone_Renamed);
				}
			}
			return this;
		}
Esempio n. 29
0
        //-----------------------------------------------------------------------
        /// <summary>
        /// Writes the state to the stream.
        /// </summary>
        /// <param name="offset">  the offset, not null </param>
        /// <param name="out">  the output stream, not null </param>
        /// <exception cref="IOException"> if an error occurs </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void writeOffset(java.time.ZoneOffset offset, java.io.DataOutput out) throws java.io.IOException
        internal static void WriteOffset(ZoneOffset offset, DataOutput @out)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int offsetSecs = offset.getTotalSeconds();
            int offsetSecs = offset.TotalSeconds;
            int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127;             // compress to -72 to +72

            @out.WriteByte(offsetByte);
            if (offsetByte == 127)
            {
                @out.WriteInt(offsetSecs);
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Creates an instance.
        /// </summary>
        /// <param name="baseStandardOffset">  the standard offset to use before legal rules were set, not null </param>
        /// <param name="baseWallOffset">  the wall offset to use before legal rules were set, not null </param>
        /// <param name="standardOffsetTransitionList">  the list of changes to the standard offset, not null </param>
        /// <param name="transitionList">  the list of transitions, not null </param>
        /// <param name="lastRules">  the recurring last rules, size 16 or less, not null </param>
        internal ZoneRules(ZoneOffset baseStandardOffset, ZoneOffset baseWallOffset, IList <ZoneOffsetTransition> standardOffsetTransitionList, IList <ZoneOffsetTransition> transitionList, IList <ZoneOffsetTransitionRule> lastRules) : base()
        {
            // convert standard transitions

            this.StandardTransitions = new long[standardOffsetTransitionList.Count];

            this.StandardOffsets    = new ZoneOffset[standardOffsetTransitionList.Count + 1];
            this.StandardOffsets[0] = baseStandardOffset;
            for (int i = 0; i < standardOffsetTransitionList.Count; i++)
            {
                this.StandardTransitions[i] = standardOffsetTransitionList[i].ToEpochSecond();
                this.StandardOffsets[i + 1] = standardOffsetTransitionList[i].OffsetAfter;
            }

            // convert savings transitions to locals
            IList <LocalDateTime> localTransitionList       = new List <LocalDateTime>();
            IList <ZoneOffset>    localTransitionOffsetList = new List <ZoneOffset>();

            localTransitionOffsetList.Add(baseWallOffset);
            foreach (ZoneOffsetTransition trans in transitionList)
            {
                if (trans.Gap)
                {
                    localTransitionList.Add(trans.DateTimeBefore);
                    localTransitionList.Add(trans.DateTimeAfter);
                }
                else
                {
                    localTransitionList.Add(trans.DateTimeAfter);
                    localTransitionList.Add(trans.DateTimeBefore);
                }
                localTransitionOffsetList.Add(trans.OffsetAfter);
            }
            this.SavingsLocalTransitions = localTransitionList.ToArray();
            this.WallOffsets             = localTransitionOffsetList.ToArray();

            // convert savings transitions to instants
            this.SavingsInstantTransitions = new long[transitionList.Count];
            for (int i = 0; i < transitionList.Count; i++)
            {
                this.SavingsInstantTransitions[i] = transitionList[i].ToEpochSecond();
            }

            // last rules
            if (lastRules.Count > 16)
            {
                throw new IllegalArgumentException("Too many transition rules");
            }
            this.LastRules = lastRules.ToArray();
        }