internal static bool TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result) { result = DateTime.MinValue; DateTimeResult resultData = new DateTimeResult(); // The buffer to store the parsing result. resultData.Init(); if (TryParseExact(s, format, dtfi, style, ref resultData)) { result = resultData.parsedDate; return true; } return false; }
internal static DateTime ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style) { DateTimeResult result = new DateTimeResult(); // The buffer to store the parsing result. result.Init(); if (TryParseExact(s, format, dtfi, style, ref result)) { return result.parsedDate; } else { throw GetDateTimeParseException(ref result); } }
internal static DateTime ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, out TimeSpan offset) { DateTimeResult result = new DateTimeResult(); // The buffer to store the parsing result. offset = TimeSpan.Zero; result.Init(); result.flags |= ParseFlags.CaptureOffset; if (TryParseExact(s, format, dtfi, style, ref result)) { offset = result.timeZoneOffset; return result.parsedDate; } else { throw GetDateTimeParseException(ref result); } }
internal static bool TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result, out TimeSpan offset) { result = DateTime.MinValue; offset = TimeSpan.Zero; DateTimeResult resultData = new DateTimeResult(); // The buffer to store the parsing result. resultData.Init(); resultData.flags |= ParseFlags.CaptureOffset; if (TryParseExact(s, format, dtfi, style, ref resultData)) { result = resultData.parsedDate; offset = resultData.timeZoneOffset; return true; } return false; }
internal static bool TryParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style, out DateTime result) { DateTimeFormatInfo dtfi = provider == null ? DateTimeFormatInfo.CurrentInfo : DateTimeFormatInfo.GetInstance(provider); result = DateTime.MinValue; DateTimeResult resultData = new DateTimeResult(); // The buffer to store the parsing result. resultData.Init(); if (TryParseExact(s, format, dtfi, style, ref resultData)) { result = resultData.parsedDate; return true; } return false; }
internal static DateTime ParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style) { DateTimeFormatInfo dtfi = provider == null ? DateTimeFormatInfo.CurrentInfo : DateTimeFormatInfo.GetInstance(provider); DateTimeResult result = new DateTimeResult(); // The buffer to store the parsing result. result.Init(); if (TryParseExact(s, format, dtfi, style, ref result)) { return result.parsedDate; } else { throw GetDateTimeParseException(ref result); } }
internal static bool TryParse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles, out DateTime result, out TimeSpan offset) { result = DateTime.MinValue; offset = TimeSpan.Zero; DateTimeResult parseResult = new DateTimeResult(); // The buffer to store the parsing result. parseResult.Init(); parseResult.flags |= ParseFlags.CaptureOffset; if (TryParse(s, dtfi, styles, ref parseResult)) { result = parseResult.parsedDate; offset = parseResult.timeZoneOffset; return true; } return false; }
internal static bool TryParseExactMultiple(String s, String[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result) { if (s == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "s"); return false; } if (formats == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "formats"); return false; } if (s.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null); return false; } if (formats.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null); return false; } Contract.Assert(dtfi != null, "dtfi == null"); // // Do a loop through the provided formats and see if we can parse succesfully in // one of the formats. // for (int i = 0; i < formats.Length; i++) { if (formats[i] == null || formats[i].Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null); return false; } // Create a new result each time to ensure the runs are independent. Carry through // flags from the caller and return the result. DateTimeResult innerResult = new DateTimeResult(); // The buffer to store the parsing result. innerResult.Init(); innerResult.flags = result.flags; if (TryParseExact(s, formats[i], dtfi, style, ref innerResult)) { result.parsedDate = innerResult.parsedDate; result.timeZoneOffset = innerResult.timeZoneOffset; return (true); } } result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null); return (false); }
internal static bool TryParse(String s, IFormatProvider provider, DateTimeStyles styles, out DateTime result) { DateTimeFormatInfo dtfi = provider == null ? DateTimeFormatInfo.CurrentInfo : DateTimeFormatInfo.GetInstance(provider); result = DateTime.MinValue; DateTimeResult parseResult = new DateTimeResult(); // The buffer to store the parsing result. parseResult.Init(); if (TryParse(s, dtfi, styles, ref parseResult)) { result = parseResult.parsedDate; return true; } return false; }
internal static DateTime Parse(String s, IFormatProvider provider, DateTimeStyles styles, out TimeSpan offset) { DateTimeFormatInfo dtfi = provider == null ? DateTimeFormatInfo.CurrentInfo : DateTimeFormatInfo.GetInstance(provider); DateTimeResult result = new DateTimeResult(); // The buffer to store the parsing result. result.Init(); result.flags |= ParseFlags.CaptureOffset; if (TryParse(s, dtfi, styles, ref result)) { offset = result.timeZoneOffset; return result.parsedDate; } else { throw GetDateTimeParseException(ref result); } }
internal static bool TryParseExactMultiple(String s, String[] formats, IFormatProvider provider, DateTimeStyles style, out DateTime result, out TimeSpan offset) { DateTimeFormatInfo dtfi = provider == null ? DateTimeFormatInfo.CurrentInfo : DateTimeFormatInfo.GetInstance(provider); result = DateTime.MinValue; offset = TimeSpan.Zero; DateTimeResult resultData = new DateTimeResult(); // The buffer to store the parsing result. resultData.Init(); resultData.flags |= ParseFlags.CaptureOffset; if (TryParseExactMultiple(s, formats, dtfi, style, ref resultData)) { result = resultData.parsedDate; offset = resultData.timeZoneOffset; return true; } return false; }
internal static bool TryParseExactMultiple(string s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result, out TimeSpan offset) { result = DateTime.MinValue; offset = TimeSpan.Zero; DateTimeResult result2 = new DateTimeResult(); result2.Init(); result2.flags |= ParseFlags.CaptureOffset; if (TryParseExactMultiple(s, formats, dtfi, style, ref result2)) { result = result2.parsedDate; offset = result2.timeZoneOffset; return true; } return false; }
internal static bool TryParseExactMultiple(string s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result) { if (s == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "s"); return false; } if (formats == null) { result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "formats"); return false; } if (s.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null); return false; } if (formats.Length == 0) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null); return false; } for (int i = 0; i < formats.Length; i++) { if ((formats[i] == null) || (formats[i].Length == 0)) { result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null); return false; } DateTimeResult result2 = new DateTimeResult(); result2.Init(); result2.flags = result.flags; if (TryParseExact(s, formats[i], dtfi, style, ref result2)) { result.parsedDate = result2.parsedDate; result.timeZoneOffset = result2.timeZoneOffset; return true; } } result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null); return false; }
internal static bool TryParseExactMultiple(string s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result) { result = DateTime.MinValue; DateTimeResult result2 = new DateTimeResult(); result2.Init(); if (TryParseExactMultiple(s, formats, dtfi, style, ref result2)) { result = result2.parsedDate; return true; } return false; }
internal static DateTime ParseExactMultiple(string s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, out TimeSpan offset) { DateTimeResult result = new DateTimeResult(); offset = TimeSpan.Zero; result.Init(); result.flags |= ParseFlags.CaptureOffset; if (!TryParseExactMultiple(s, formats, dtfi, style, ref result)) { throw GetDateTimeParseException(ref result); } offset = result.timeZoneOffset; return result.parsedDate; }
internal static DateTime ParseExactMultiple(string s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style) { DateTimeResult result = new DateTimeResult(); result.Init(); if (!TryParseExactMultiple(s, formats, dtfi, style, ref result)) { throw GetDateTimeParseException(ref result); } return result.parsedDate; }