/// <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);
		}
Ejemplo n.º 2
0
 /// <summary>
 /// Normalizes the time-zone ID, returning a {@code ZoneOffset} where possible.
 /// <para>
 /// The returns a normalized {@code ZoneId} that can be used in place of this ID.
 /// The result will have {@code ZoneRules} equivalent to those returned by this object,
 /// however the ID returned by {@code getId()} may be different.
 /// </para>
 /// <para>
 /// The normalization checks if the rules of this {@code ZoneId} have a fixed offset.
 /// If they do, then the {@code ZoneOffset} equal to that offset is returned.
 /// Otherwise {@code this} is returned.
 ///
 /// </para>
 /// </summary>
 /// <returns> the time-zone unique ID, not null </returns>
 public virtual ZoneId Normalized()
 {
     try
     {
         ZoneRules rules = Rules;
         if (rules.FixedOffset)
         {
             return(rules.GetOffset(Instant.EPOCH));
         }
     }
     catch (ZoneRulesException)
     {
         // invalid ZoneRegion is not important to this method
     }
     return(this);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the Coordinated Universal Time (UTC) that corresponds to a specified time.
        /// </summary>
        /// <param name="datetime">A date and time.</param>
        /// <param name="optimize">Value which indicates whether to optimize the convert</param>
        /// <returns>A <see cref="DateTime"/> object whose value is the Coordinated Universal Time (UTC) that corresponds to time.</returns>
        public DateTime ToUniversalTime(DateTime datetime, bool optimize = false)
        {
            if (datetime.Kind == DateTimeKind.Unspecified)
            {
                throw new ArgumentException("Unspecified date time kind", nameof(datetime));
            }

            if (datetime.Kind == DateTimeKind.Utc)
            {
                return(datetime);
            }

            // Check that local date is cover by zone
            if (!ZoneRules.Any(z => datetime >= z.StartZone.ToLocalTime() && datetime < z.EndZone.ToLocalTime()))
            {
                throw new ArgumentOutOfRangeException(nameof(datetime));
            }

            if (optimize)
            {
                UpdateDateChange(datetime.Year);
                List <TzTimeZoneRuleDate> knownDate = _zoneDates[datetime.Year];
                if (knownDate.Any())
                {
                    foreach (var elt in knownDate)
                    {
                        if ((datetime.Kind == DateTimeKind.Utc && datetime < elt.UtcDate) ||
                            (datetime.Kind == DateTimeKind.Local && datetime < elt.ToLocalTime()))
                        {
                            return(TzUtilities.GetDateTime(datetime, elt.GmtOffset, elt.StandardOffset, DateTimeKind.Utc));
                        }
                    }
                }
            }

            ZoneRuleAssociate zr = GetZoneRule(datetime);

            Debug.Assert(zr.zoneRule != null);

            TimeSpan gmtOffset = zr.zoneRule.GmtOffset;

            DateTime utcclock = datetime.Add(-gmtOffset - zr.standardOffset);

            return(new DateTime(utcclock.Ticks, DateTimeKind.Utc));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Obtains an instance of {@code ZoneId} from an identifier.
        /// </summary>
        /// <param name="zoneId">  the time-zone ID, not null </param>
        /// <param name="checkAvailable">  whether to check if the zone ID is available </param>
        /// <returns> the zone ID, not null </returns>
        /// <exception cref="DateTimeException"> if the ID format is invalid </exception>
        /// <exception cref="ZoneRulesException"> if checking availability and the ID cannot be found </exception>
        internal static ZoneRegion OfId(String zoneId, bool checkAvailable)
        {
            Objects.RequireNonNull(zoneId, "zoneId");
            CheckName(zoneId);
            ZoneRules rules = null;

            try
            {
                // always attempt load for better behavior after deserialization
                rules = ZoneRulesProvider.GetRules(zoneId, true);
            }
            catch (ZoneRulesException ex)
            {
                if (checkAvailable)
                {
                    throw ex;
                }
            }
            return(new ZoneRegion(zoneId, rules));
        }
		//-----------------------------------------------------------------------
		/// <summary>
		/// Obtains an instance from a local date-time using the preferred offset if possible.
		/// </summary>
		/// <param name="localDateTime">  the local date-time, not null </param>
		/// <param name="zone">  the zone identifier, not null </param>
		/// <param name="preferredOffset">  the zone offset, null if no preference </param>
		/// <returns> the zoned date-time, not null </returns>
		internal static ChronoZonedDateTime<R> ofBest<R>(ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset) where R : ChronoLocalDate
		{
			Objects.RequireNonNull(localDateTime, "localDateTime");
			Objects.RequireNonNull(zone, "zone");
			if (zone is ZoneOffset)
			{
				return new ChronoZonedDateTimeImpl<>(localDateTime, (ZoneOffset) zone, zone);
			}
			ZoneRules rules = zone.Rules;
			LocalDateTime isoLDT = LocalDateTime.From(localDateTime);
			IList<ZoneOffset> validOffsets = rules.GetValidOffsets(isoLDT);
			ZoneOffset offset;
			if (validOffsets.Count == 1)
			{
				offset = validOffsets[0];
			}
			else if (validOffsets.Count == 0)
			{
				ZoneOffsetTransition trans = rules.GetTransition(isoLDT);
				localDateTime = localDateTime.PlusSeconds(trans.Duration.Seconds);
				offset = trans.OffsetAfter;
			}
			else
			{
				if (preferredOffset != null && validOffsets.Contains(preferredOffset))
				{
					offset = preferredOffset;
				}
				else
				{
					offset = validOffsets[0];
				}
			}
			Objects.RequireNonNull(offset, "offset"); // protect against bad ZoneRules
			return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone);
		}
Ejemplo n.º 6
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="id">  the time-zone ID, not null </param>
 /// <param name="rules">  the rules, null for lazy lookup </param>
 internal ZoneRegion(String id, ZoneRules rules)
 {
     this.Id_Renamed    = id;
     this.Rules_Renamed = rules;
 }
Ejemplo n.º 7
0
        public static void RegisterMap(int mapIndex, int mapID, int fileIndex, int width, int height, int season, string name, ZoneRules rules)
        {
            Map newMap = new Map(mapID, mapIndex, fileIndex, width, height, season, name, rules);

            Map.Maps[mapIndex] = newMap;
            Map.AllMaps.Add(newMap);
        }