static private ConvertJavaScriptTicksToDateTime ( long javaScriptTicks ) : System.DateTime | ||
javaScriptTicks | long | |
return | System.DateTime |
private static bool TryParseDateTimeOffsetMicrosoft(StringReference text, out DateTimeOffset dt) { long ticks; TimeSpan offset; if (!DateTimeUtils.TryParseMicrosoftDate(text, out ticks, out offset, out DateTimeKind _)) { dt = (DateTimeOffset) new DateTime(); return(false); } DateTime dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(ticks); dt = new DateTimeOffset(dateTime.Add(offset).Ticks, offset); return(true); }
private static bool TryParseDateTimeOffsetMicrosoft(StringReference text, out DateTimeOffset dt) { long num; TimeSpan timeSpan; DateTimeKind dateTimeKind; DateTime dateTime; if (!DateTimeUtils.TryParseMicrosoftDate(text, out num, out timeSpan, out dateTimeKind)) { dateTime = new DateTime(); dt = dateTime; return(false); } dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(num).Add(timeSpan); dt = new DateTimeOffset(dateTime.Ticks, timeSpan); return(true); }
private static bool TryParseDateMicrosoft(string text, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, out object dt) { string text2 = text.Substring(6, text.Length - 8); DateTimeKind dateTimeKind = DateTimeKind.Utc; int num = text2.IndexOf('+', 1); if (num == -1) { num = text2.IndexOf('-', 1); } TimeSpan timeSpan = TimeSpan.Zero; if (num != -1) { dateTimeKind = DateTimeKind.Local; timeSpan = DateTimeUtils.ReadOffset(text2.Substring(num)); text2 = text2.Substring(0, num); } long javaScriptTicks = long.Parse(text2, NumberStyles.Integer, CultureInfo.InvariantCulture); DateTime dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(javaScriptTicks); if (dateParseHandling == DateParseHandling.DateTimeOffset) { dt = new DateTimeOffset(dateTime.Add(timeSpan).Ticks, timeSpan); return(true); } DateTime value; switch (dateTimeKind) { case DateTimeKind.Unspecified: value = DateTime.SpecifyKind(dateTime.ToLocalTime(), DateTimeKind.Unspecified); goto IL_D1; case DateTimeKind.Local: value = dateTime.ToLocalTime(); goto IL_D1; } value = dateTime; IL_D1: dt = DateTimeUtils.EnsureDateTime(value, dateTimeZoneHandling); return(true); }
public static bool TryGetDateFromConstructorJson( JsonReader reader, out DateTime dateTime, [NotNullWhen(false)] out string?errorMessage ) { dateTime = default; errorMessage = null; if (!TryGetDateConstructorValue(reader, out long?t1, out errorMessage) || t1 == null) { errorMessage = errorMessage ?? "Date constructor has no arguments."; return(false); } if (!TryGetDateConstructorValue(reader, out long?t2, out errorMessage)) { return(false); } else if (t2 != null) { // Only create a list when there is more than one argument List <long> dateArgs = new List <long> { t1.Value, t2.Value }; while (true) { if (!TryGetDateConstructorValue(reader, out long?integer, out errorMessage)) { return(false); } else if (integer != null) { dateArgs.Add(integer.Value); } else { break; } } if (dateArgs.Count > 7) { errorMessage = "Unexpected number of arguments when reading date constructor."; return(false); } // Pad args out to the number used by the ctor while (dateArgs.Count < 7) { dateArgs.Add(0); } dateTime = new DateTime( (int)dateArgs[0], (int)dateArgs[1] + 1, dateArgs[2] == 0 ? 1 : (int)dateArgs[2], (int)dateArgs[3], (int)dateArgs[4], (int)dateArgs[5], (int)dateArgs[6] ); } else { dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(t1.Value); } return(true); }