<commit_before>﻿#region Copyright and license information
// Copyright 2001-2009 <NAME>
// Copyright 2009-2010 <NAME>
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using System;

namespace NodaTime
{
    /// <summary>
    /// A date and time with an associated chronology - or to look at it
    /// a different way, a LocalDateTime plus a time zone.
    /// </summary>
    /// <remarks>
    /// <para>
    /// Some seemingly valid values do not represent a valid instant due to
    /// the local time moving forward during a daylight saving transition, thus "skipping"
    /// the given value. Other values occur twice (due to local time moving backward),
    /// in which case a ZonedDateTime will always represent the later of the two
    /// possible times, when converting it to an instant.
    /// </para>
    /// <para>
    /// A value constructed with "new ZonedDateTime()" will represent the Unix epoch
    /// in the ISO calendar system in the UTC time zone. That is the only situation in which
    /// the chronology is assumed rather than specified.
    /// </para>
    /// </remarks>
    public struct ZonedDateTime
    {
        private readonly Instant instant;
        private readonly Chronology chronology;

        public ZonedDateTime(LocalDateTime localDateTime, IDateTimeZone zone)
        {
            if (zone == null)
            {
                throw new ArgumentNullException("zone");
            } 
            instant = ConvertLocalToUtc(localDateTime.LocalInstant, zone);
            chronology = new Chronology(zone, localDateTime.Calendar);
        }

        public ZonedDateTime(Instant instant, Chronology chronology)
        {
            if (chronology == null)
            {
                throw new ArgumentNullException("chronology");
            }
            this.instant = instant;
            this.chronology = chronology;
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             IDateTimeZone zone)
            : this(year, month, day, hour, minute, second, Chronology.IsoForZone(zone))
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             Chronology chronology)
            : this(year, month, day, hour, minute, second, 0, 0, chronology)
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             int millisecond, IDateTimeZone zone)
            : this(year, month, day, hour, minute, second, millisecond, Chronology.IsoForZone(zone))
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             int millisecond, Chronology chronology)
            : this(year, month, day, hour, minute, second, millisecond, 0, chronology)
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             int millisecond, int tick, IDateTimeZone zone)
            : this(year, month, day, hour, minute, second, millisecond, tick, Chronology.IsoForZone(zone))
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             int millisecond, int tick, Chronology chronology)
        {
            if (chronology == null)
            {
                throw new ArgumentNullException("chronology");
            }
            LocalInstant localInstant = chronology.Calendar.GetLocalInstant(year, month, day, hour, minute, second, millisecond, tick);
            instant = ConvertLocalToUtc(localInstant, chronology.Zone);
            this.chronology = chronology;
        }

        private static Instant ConvertLocalToUtc(LocalInstant localInstant, IDateTimeZone zone)
        {
            // This call will throw SkippedTimeException if necessary
            Offset offset = zone.GetOffsetFromLocal(localInstant);
            Instant instant = localInstant - offset;
            return instant;
        }

        /// <summary>
        /// Converts this value to the instant it represents on the time line.
        /// If two instants are represented by the same set of values, the later
        /// instant is returned.
        /// </summary>
        /// <remarks>
        /// Conceptually this is a conversion (which is why it's not a property) but
        /// in reality the conversion is done at the point of construction.
        /// </remarks>
        public Instant ToInstant()
        {
            return instant;
        }

        /// <summary>
        /// Returns the chronology associated with this date and time.
        /// </summary>
        public Chronology Chronology { get { return chronology; } }

        public IDateTimeZone Zone { get { return Chronology.Zone; } }

        public LocalInstant LocalInstant { get { return instant + Zone.GetOffsetFromUtc(instant); } }
<commit_msg>Remove redundant offset check (now handled in GetOffsetFromLocal) and changed internal structure - we now maintain a LocalInstant and an Offset instead of just an Instant. This makes the type slightly bigger, but is conceptually cleaner - and is likely to increase efficiency as so many properties rely on the local instant.<commit_after>﻿#region Copyright and license information
// Copyright 2001-2009 <NAME>
// Copyright 2009-2010 <NAME>
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using System;

namespace NodaTime
{
    /// <summary>
    /// A date and time with an associated chronology - or to look at it
    /// a different way, a LocalDateTime plus a time zone.
    /// </summary>
    /// <remarks>
    /// <para>
    /// Some seemingly valid values do not represent a valid instant due to
    /// the local time moving forward during a daylight saving transition, thus "skipping"
    /// the given value. Other values occur twice (due to local time moving backward),
    /// in which case a ZonedDateTime will always represent the later of the two
    /// possible times, when converting it to an instant.
    /// </para>
    /// <para>
    /// A value constructed with "new ZonedDateTime()" will represent the Unix epoch
    /// in the ISO calendar system in the UTC time zone. That is the only situation in which
    /// the chronology is assumed rather than specified.
    /// </para>
    /// </remarks>
    public struct ZonedDateTime
    {
        private readonly LocalInstant localInstant;
        private readonly Chronology chronology;
        private readonly Offset offset;

        public ZonedDateTime(LocalDateTime localDateTime, IDateTimeZone zone)
        {
            if (zone == null)
            {
                throw new ArgumentNullException("zone");
            }
            localInstant = localDateTime.LocalInstant;
            offset = zone.GetOffsetFromLocal(localInstant);
            chronology = new Chronology(zone, localDateTime.Calendar);
        }

        public ZonedDateTime(Instant instant, Chronology chronology)
        {
            if (chronology == null)
            {
                throw new ArgumentNullException("chronology");
            }
            offset = chronology.Zone.GetOffsetFromUtc(instant);
            localInstant = instant + offset;
            this.chronology = chronology;
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             IDateTimeZone zone)
            : this(year, month, day, hour, minute, second, Chronology.IsoForZone(zone))
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             Chronology chronology)
            : this(year, month, day, hour, minute, second, 0, 0, chronology)
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             int millisecond, IDateTimeZone zone)
            : this(year, month, day, hour, minute, second, millisecond, Chronology.IsoForZone(zone))
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             int millisecond, Chronology chronology)
            : this(year, month, day, hour, minute, second, millisecond, 0, chronology)
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             int millisecond, int tick, IDateTimeZone zone)
            : this(year, month, day, hour, minute, second, millisecond, tick, Chronology.IsoForZone(zone))
        {
        }

        public ZonedDateTime(int year, int month, int day,
                             int hour, int minute, int second,
                             int millisecond, int tick, Chronology chronology)
        {
            if (chronology == null)
            {
                throw new ArgumentNullException("chronology");
            }
            localInstant = chronology.Calendar.GetLocalInstant(year, month, day, hour, minute, second, millisecond, tick);
            offset = chronology.Zone.GetOffsetFromLocal(localInstant);
            this.chronology = chronology;
        }

        /// <summary>
        /// Converts this value to the instant it represents on the time line.
        /// If two instants are represented by the same set of values, the later
        /// instant is returned.
        /// </summary>
        /// <remarks>
        /// Conceptually this is a conversion (which is why it's not a property) but
        /// in reality the conversion is done at the point of construction.
        /// </remarks>
        public Instant ToInstant()
        {
            return localInstant - offset;
        }

        /// <summary>
        /// Returns the chronology associated with this date and time.
        /// </summary>
        public Chronology Chronology { get { return chronology; } }

        public IDateTimeZone Zone { get { return Chronology.Zone; } }

        public LocalInstant LocalInstant { get { return localInstant; } }

{'fraction_non_alphanumeric': 0.08121432278152568, 'fraction_numerical': 0.0039785504238021106, 'mean_word_length': 1.9001755706044645, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5423788', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2756, 'n_words': 1112}