GetLocalUtcOffset() static private method

static private GetLocalUtcOffset ( System.DateTime dateTime, TimeZoneInfoOptions flags ) : System.TimeSpan
dateTime System.DateTime
flags TimeZoneInfoOptions
return System.TimeSpan
 // Token: 0x060015E8 RID: 5608 RVA: 0x00040EC8 File Offset: 0x0003F0C8
 private static void FormatCustomizedRoundripTimeZone(DateTime dateTime, TimeSpan offset, StringBuilder result)
 {
     if (offset == DateTimeFormat.NullOffset)
     {
         DateTimeKind kind = dateTime.Kind;
         if (kind == DateTimeKind.Utc)
         {
             result.Append("Z");
             return;
         }
         if (kind != DateTimeKind.Local)
         {
             return;
         }
         offset = TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
     }
     if (offset >= TimeSpan.Zero)
     {
         result.Append('+');
     }
     else
     {
         result.Append('-');
         offset = offset.Negate();
     }
     result.AppendFormat(CultureInfo.InvariantCulture, "{0:00}:{1:00}", offset.Hours, offset.Minutes);
 }
Esempio n. 2
0
        private static void FormatCustomizedRoundripTimeZone(DateTime dateTime, TimeSpan offset, StringBuilder result)
        {
            if (offset == DateTimeFormat.NullOffset)
            {
                switch (dateTime.Kind)
                {
                case DateTimeKind.Utc:
                    result.Append("Z");
                    return;

                case DateTimeKind.Local:
                    offset = TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
                    break;

                default:
                    return;
                }
            }
            if (offset >= TimeSpan.Zero)
            {
                result.Append('+');
            }
            else
            {
                result.Append('-');
                offset = offset.Negate();
            }
            result.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, "{0:00}:{1:00}", (object)offset.Hours, (object)offset.Minutes);
        }
Esempio n. 3
0
        // Constructs a DateTimeOffset from a DateTime. For Local and Unspecified kinds,
        // extracts the local offset. For UTC, creates a UTC instance with a zero offset.
        public DateTimeOffset(DateTime dateTime)
        {
            TimeSpan offset;

            if (dateTime.Kind != DateTimeKind.Utc)
            {
                // Local and Unspecified are both treated as Local
                offset = TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
            }
            else
            {
                offset = new TimeSpan(0);
            }
            m_offsetMinutes = ValidateOffset(offset);
            m_dateTime      = ValidateDate(dateTime, offset);
        }
Esempio n. 4
0
        private static DateTimeOffset ToLocalTime(DateTime utcDateTime, bool throwOnOverflow)
        {
            TimeSpan offset     = TimeZoneInfo.GetLocalUtcOffset(utcDateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
            long     localTicks = utcDateTime.Ticks + offset.Ticks;

            if (localTicks < DateTime.MinTicks || localTicks > DateTime.MaxTicks)
            {
                if (throwOnOverflow)
                {
                    throw new ArgumentException(SR.Arg_ArgumentOutOfRangeException);
                }

                localTicks = localTicks < DateTime.MinTicks ? DateTime.MinTicks : DateTime.MaxTicks;
            }

            return(new DateTimeOffset(localTicks, offset));
        }
Esempio n. 5
0
 // Constructs a DateTimeOffset from a DateTime. And an offset. Always makes the clock time
 // consistent with the DateTime. For Utc ensures the offset is zero. For local, ensures that
 // the offset corresponds to the local.
 public DateTimeOffset(DateTime dateTime, TimeSpan offset)
 {
     if (dateTime.Kind == DateTimeKind.Local)
     {
         if (offset != TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime))
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_OffsetLocalMismatch"), "offset");
         }
     }
     else if (dateTime.Kind == DateTimeKind.Utc)
     {
         if (offset != TimeSpan.Zero)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_OffsetUtcMismatch"), "offset");
         }
     }
     m_offsetMinutes = ValidateOffset(offset);
     m_dateTime      = ValidateDate(dateTime, offset);
 }
Esempio n. 6
0
 // Constructs a DateTimeOffset from a DateTime. And an offset. Always makes the clock time
 // consistent with the DateTime. For Utc ensures the offset is zero. For local, ensures that
 // the offset corresponds to the local.
 public DateTimeOffset(DateTime dateTime, TimeSpan offset)
 {
     if (dateTime.Kind == DateTimeKind.Local)
     {
         if (offset != TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime))
         {
             throw new ArgumentException(SR.Argument_OffsetLocalMismatch, nameof(offset));
         }
     }
     else if (dateTime.Kind == DateTimeKind.Utc)
     {
         if (offset != TimeSpan.Zero)
         {
             throw new ArgumentException(SR.Argument_OffsetUtcMismatch, nameof(offset));
         }
     }
     _offsetMinutes = ValidateOffset(offset);
     _dateTime      = ValidateDate(dateTime, offset);
 }
Esempio n. 7
0
 private static void FormatCustomizedTimeZone(DateTime dateTime, TimeSpan offset, string format, int tokenLen, bool timeOnly, StringBuilder result)
 {
     if (offset == DateTimeFormat.NullOffset)
     {
         if (timeOnly && dateTime.Ticks < 864000000000L)
         {
             offset = TimeZoneInfo.GetLocalUtcOffset(DateTime.Now, TimeZoneInfoOptions.NoThrowOnInvalidTime);
         }
         else if (dateTime.Kind == DateTimeKind.Utc)
         {
             DateTimeFormat.InvalidFormatForUtc(format, dateTime);
             dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Local);
             offset   = TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
         }
         else
         {
             offset = TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
         }
     }
     if (offset >= TimeSpan.Zero)
     {
         result.Append('+');
     }
     else
     {
         result.Append('-');
         offset = offset.Negate();
     }
     if (tokenLen <= 1)
     {
         result.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, "{0:0}", (object)offset.Hours);
     }
     else
     {
         result.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, "{0:00}", (object)offset.Hours);
         if (tokenLen < 3)
         {
             return;
         }
         result.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, ":{0:00}", (object)offset.Minutes);
     }
 }