TryParseDateTimeOffsetExact() private static method

private static TryParseDateTimeOffsetExact ( string text, string dateFormatString, CultureInfo culture, DateTimeOffset &dt ) : bool
text string
dateFormatString string
culture System.Globalization.CultureInfo
dt DateTimeOffset
return bool
Esempio n. 1
0
 internal static bool TryParseDateTimeOffset(
     string s,
     string dateFormatString,
     CultureInfo culture,
     out DateTimeOffset dt)
 {
     if (s.Length > 0)
     {
         if (s[0] == '/')
         {
             if (s.Length >= 9 && s.StartsWith("/Date(", StringComparison.Ordinal) && (s.EndsWith(")/", StringComparison.Ordinal) && DateTimeUtils.TryParseDateTimeOffsetMicrosoft(new StringReference(s.ToCharArray(), 0, s.Length), out dt)))
             {
                 return(true);
             }
         }
         else if (s.Length >= 19 && s.Length <= 40 && (char.IsDigit(s[0]) && s[10] == 'T') && (DateTimeOffset.TryParseExact(s, "yyyy-MM-ddTHH:mm:ss.FFFFFFFK", (IFormatProvider)CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dt) && DateTimeUtils.TryParseDateTimeOffsetIso(new StringReference(s.ToCharArray(), 0, s.Length), out dt)))
         {
             return(true);
         }
         if (!string.IsNullOrEmpty(dateFormatString) && DateTimeUtils.TryParseDateTimeOffsetExact(s, dateFormatString, culture, out dt))
         {
             return(true);
         }
     }
     dt = new DateTimeOffset();
     return(false);
 }
Esempio n. 2
0
 internal static bool TryParseDateTimeOffset(
     StringReference s,
     string dateFormatString,
     CultureInfo culture,
     out DateTimeOffset dt)
 {
     if (s.Length > 0)
     {
         int startIndex = s.StartIndex;
         if (s[startIndex] == '/')
         {
             if (s.Length >= 9 && s.StartsWith("/Date(") && (s.EndsWith(")/") && DateTimeUtils.TryParseDateTimeOffsetMicrosoft(s, out dt)))
             {
                 return(true);
             }
         }
         else if (s.Length >= 19 && s.Length <= 40 && (char.IsDigit(s[startIndex]) && s[startIndex + 10] == 'T') && DateTimeUtils.TryParseDateTimeOffsetIso(s, out dt))
         {
             return(true);
         }
         if (!string.IsNullOrEmpty(dateFormatString) && DateTimeUtils.TryParseDateTimeOffsetExact(s.ToString(), dateFormatString, culture, out dt))
         {
             return(true);
         }
     }
     dt = new DateTimeOffset();
     return(false);
 }