/// <summary> /// Internal constructor from pre-validated values. /// </summary> internal ZonedDateTime(OffsetDateTime offsetDateTime, DateTimeZone zone) { this.offsetDateTime = offsetDateTime; this.zone = zone; }
/// <summary> /// Initializes a new instance of the <see cref="ZonedDateTime"/> struct. /// </summary> /// <param name="instant">The instant.</param> /// <param name="zone">The time zone.</param> /// <param name="calendar">The calendar system.</param> public ZonedDateTime(Instant instant, DateTimeZone zone, CalendarSystem calendar) { this.zone = Preconditions.CheckNotNull(zone, nameof(zone)); offsetDateTime = new OffsetDateTime(instant, zone.GetUtcOffset(instant), Preconditions.CheckNotNull(calendar, nameof(calendar))); }
/// <summary> /// Initializes a new instance of the <see cref="ZonedDateTime" /> struct in the specified time zone /// and the ISO calendar. /// </summary> /// <param name="instant">The instant.</param> /// <param name="zone">The time zone.</param> public ZonedDateTime(Instant instant, DateTimeZone zone) { this.zone = Preconditions.CheckNotNull(zone, nameof(zone)); offsetDateTime = new OffsetDateTime(instant, zone.GetUtcOffset(instant)); }
/// <inheritdoc /> public override bool Equals(OffsetDateTime x, OffsetDateTime y) => x.ToElapsedTimeSinceEpoch() == y.ToElapsedTimeSinceEpoch();
/// <inheritdoc /> public override int GetHashCode(OffsetDateTime obj) => obj.ToElapsedTimeSinceEpoch().GetHashCode();
/// <inheritdoc /> public override int GetHashCode(OffsetDateTime obj) => HashCodeHelper.Hash(obj.yearMonthDayCalendar, obj.NanosecondOfDay);
/// <inheritdoc /> public override int Compare(OffsetDateTime x, OffsetDateTime y) => // TODO(2.0): Optimize cases which are more than 2 days apart, by avoiding the arithmetic? x.ToElapsedTimeSinceEpoch().CompareTo(y.ToElapsedTimeSinceEpoch());
/// <inheritdoc /> public override bool Equals(OffsetDateTime x, OffsetDateTime y) => x.yearMonthDayCalendar == y.yearMonthDayCalendar && x.NanosecondOfDay == y.NanosecondOfDay;
/// <inheritdoc /> public override int Compare(OffsetDateTime x, OffsetDateTime y) { return(x.ToInstant().CompareTo(y.ToInstant())); }
/// <inheritdoc /> public override int Compare(OffsetDateTime x, OffsetDateTime y) { return(x.localDateTime.LocalInstant.CompareTo(y.localDateTime.LocalInstant)); }
/// <inheritdoc /> public override int GetHashCode(OffsetDateTime obj) => HashCodeHelper.Hash(obj.localDate, obj.NanosecondOfDay);
/// <inheritdoc /> public override bool Equals(OffsetDateTime x, OffsetDateTime y) => x.localDate == y.localDate && x.NanosecondOfDay == y.NanosecondOfDay;