예제 #1
0
        /// <summary>
        /// Converts the time in a specified time zone to Coordinated Universal Time (UTC).
        /// </summary>
        /// <param name="dateTime">The Coordinated Universal Time (UTC).</param>
        /// <param name="srcTimeZone">The time zone of the <paramref name="dateTime" />.</param>
        /// <returns>
        /// The Coordinated Universal Time (UTC) that corresponds to the dateTime parameter.
        /// Its <see cref="DateTime.Kind" /> is <see cref="DateTimeKind.Utc" />.
        /// </returns>
        public static DateTime ToUtc(DateTime dateTime, TimeZoneBase srcTimeZone)
        {
            if (dateTime.Kind != DateTimeKind.Utc)
            {
                dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified);
                return(srcTimeZone.ConvertTime(dateTime, UtcZone));
            }

            return(dateTime);
        }
예제 #2
0
        /// <inheritdoc />
        public override DateTime ConvertTime(DateTime dateTime, TimeZoneBase destTimeZone)
        {
            Requires.That(dateTime.Kind != DateTimeKind.Local, "dateTime is local date time");

            dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);

            if (destTimeZone != this)
            {
                return(TimeZoneInfo.ConvertTime(dateTime, destTimeZone.Info));
            }

            return(dateTime);
        }
예제 #3
0
 /// <inheritdoc />
 public override DateTime ConvertTime(DateTime dateTime, TimeZoneBase destTimeZone)
 => TimeZoneInfo.ConvertTime(dateTime, Info, destTimeZone.Info);
예제 #4
0
 /// <summary>
 /// Converts the time in a specified time zone to Coordinated Universal Time (UTC).
 /// </summary>
 /// <param name="dateTime">The Coordinated Universal Time (UTC).</param>
 /// <param name="srcTimeZone">The time zone of the <paramref name="dateTime" />.</param>
 /// <returns>
 /// The Coordinated Universal Time (UTC) that corresponds to the <paramref name="dateTime"/> parameter.
 /// Its <see cref="DateTime.Kind" /> is <see cref="DateTimeKind.Utc" />.
 /// </returns>
 public static DateTime?ToUtc(DateTime?dateTime, TimeZoneBase srcTimeZone)
 => dateTime == null ? (DateTime?)null : ToUtc(dateTime.Value, srcTimeZone);
예제 #5
0
        /// <summary>
        /// Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.
        /// </summary>
        /// <param name="dateTime">The Coordinated Universal Time (UTC).</param>
        /// <param name="destTimeZone">
        /// The time zone to convert the <paramref name="dateTime" /> to.
        /// </param>
        /// <returns>
        /// The date and time in the destination time zone. Its <see cref="DateTime.Kind" />
        /// is <see cref="DateTimeKind.Utc" /> if <paramref name="destTimeZone"/> is UTC; otherwise,
        /// it's <see cref="DateTime.Kind" /> is <see cref="DateTimeKind.Unspecified" />.
        /// </returns>
        public static DateTime FromUtc(DateTime dateTime, TimeZoneBase destTimeZone)
        {
            Requires.That(dateTime.Kind != DateTimeKind.Local, "dateTime is local date time");

            return(UtcZone.ConvertTime(dateTime, destTimeZone));
        }
예제 #6
0
 /// <summary>
 /// Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.
 /// </summary>
 /// <param name="dateTime">The Coordinated Universal Time (UTC).</param>
 /// <param name="destTimeZone">
 /// The time zone to convert the <paramref name="dateTime" /> to.
 /// </param>
 /// <returns>
 /// The date and time in the destination time zone. Its <see cref="DateTime.Kind" />
 /// is <see cref="DateTimeKind.Utc" /> if <paramref name="destTimeZone"/> is UTC; otherwise,
 /// it's <see cref="DateTime.Kind" /> is <see cref="DateTimeKind.Unspecified" />.
 /// </returns>
 public static DateTime?FromUtc(DateTime?dateTime, TimeZoneBase destTimeZone)
 => dateTime == null ? (DateTime?)null : FromUtc(dateTime.Value, destTimeZone);