private static CreateDateTime ( Newtonsoft.Json.Utilities.DateTimeParser dateTimeParser ) : System.DateTime | ||
dateTimeParser | Newtonsoft.Json.Utilities.DateTimeParser | |
Résultat | System.DateTime |
// Token: 0x06000D1B RID: 3355 RVA: 0x0004C1B0 File Offset: 0x0004A3B0 internal static bool TryParseDateTimeIso(StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt) { DateTimeParser dateTimeParser = default(DateTimeParser); if (!dateTimeParser.Parse(text.Chars, text.StartIndex, text.Length)) { dt = default(DateTime); return(false); } DateTime dateTime = DateTimeUtils.CreateDateTime(dateTimeParser); switch (dateTimeParser.Zone) { case ParserTimeZone.Utc: dateTime = new DateTime(dateTime.Ticks, DateTimeKind.Utc); break; case ParserTimeZone.LocalWestOfUtc: { TimeSpan timeSpan = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0); long num = dateTime.Ticks + timeSpan.Ticks; if (num <= DateTime.MaxValue.Ticks) { dateTime = new DateTime(num, DateTimeKind.Utc).ToLocalTime(); } else { num += dateTime.GetUtcOffset().Ticks; if (num > DateTime.MaxValue.Ticks) { num = DateTime.MaxValue.Ticks; } dateTime = new DateTime(num, DateTimeKind.Local); } break; } case ParserTimeZone.LocalEastOfUtc: { TimeSpan timeSpan2 = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0); long num = dateTime.Ticks - timeSpan2.Ticks; if (num >= DateTime.MinValue.Ticks) { dateTime = new DateTime(num, DateTimeKind.Utc).ToLocalTime(); } else { num += dateTime.GetUtcOffset().Ticks; if (num < DateTime.MinValue.Ticks) { num = DateTime.MinValue.Ticks; } dateTime = new DateTime(num, DateTimeKind.Local); } break; } } dt = DateTimeUtils.EnsureDateTime(dateTime, dateTimeZoneHandling); return(true); }
internal static bool TryParseDateTimeIso( StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt) { DateTimeParser dateTimeParser = new DateTimeParser(); if (!dateTimeParser.Parse(text.Chars, text.StartIndex, text.Length)) { dt = new DateTime(); return(false); } DateTime d = DateTimeUtils.CreateDateTime(dateTimeParser); switch (dateTimeParser.Zone) { case ParserTimeZone.Utc: d = new DateTime(d.Ticks, DateTimeKind.Utc); break; case ParserTimeZone.LocalWestOfUtc: TimeSpan timeSpan1 = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0); long ticks1 = d.Ticks + timeSpan1.Ticks; if (ticks1 <= DateTime.MaxValue.Ticks) { d = new DateTime(ticks1, DateTimeKind.Utc).ToLocalTime(); break; } long ticks2 = ticks1 + d.GetUtcOffset().Ticks; if (ticks2 > DateTime.MaxValue.Ticks) { ticks2 = DateTime.MaxValue.Ticks; } d = new DateTime(ticks2, DateTimeKind.Local); break; case ParserTimeZone.LocalEastOfUtc: TimeSpan timeSpan2 = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0); long ticks3 = d.Ticks - timeSpan2.Ticks; if (ticks3 >= DateTime.MinValue.Ticks) { d = new DateTime(ticks3, DateTimeKind.Utc).ToLocalTime(); break; } long ticks4 = ticks3 + d.GetUtcOffset().Ticks; if (ticks4 < DateTime.MinValue.Ticks) { ticks4 = DateTime.MinValue.Ticks; } d = new DateTime(ticks4, DateTimeKind.Local); break; } dt = DateTimeUtils.EnsureDateTime(d, dateTimeZoneHandling); return(true); }
internal static bool TryParseDateTimeOffsetIso(StringReference text, out DateTimeOffset dt) { TimeSpan timeSpan; DateTimeParser dateTimeParser = new DateTimeParser(); if (!dateTimeParser.Parse(text.Chars, text.StartIndex, text.Length)) { dt = new DateTimeOffset(); return(false); } DateTime dateTime = DateTimeUtils.CreateDateTime(dateTimeParser); switch (dateTimeParser.Zone) { case ParserTimeZone.Utc: { timeSpan = new TimeSpan(0L); break; } case ParserTimeZone.LocalWestOfUtc: { timeSpan = new TimeSpan(-dateTimeParser.ZoneHour, -dateTimeParser.ZoneMinute, 0); break; } case ParserTimeZone.LocalEastOfUtc: { timeSpan = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0); break; } default: { timeSpan = TimeZoneInfo.Local.GetUtcOffset(dateTime); break; } } long ticks = dateTime.Ticks - timeSpan.Ticks; if (ticks < 0L || ticks > 3155378975999999999L) { dt = new DateTimeOffset(); return(false); } dt = new DateTimeOffset(dateTime, timeSpan); return(true); }
internal static bool TryParseDateTimeOffsetIso(StringReference text, out DateTimeOffset dt) { DateTimeParser dateTimeParser = new DateTimeParser(); if (!dateTimeParser.Parse(text.Chars, text.StartIndex, text.Length)) { dt = new DateTimeOffset(); return(false); } DateTime dateTime = DateTimeUtils.CreateDateTime(dateTimeParser); TimeSpan offset; switch (dateTimeParser.Zone) { case ParserTimeZone.Utc: offset = new TimeSpan(0L); break; case ParserTimeZone.LocalWestOfUtc: offset = new TimeSpan(-dateTimeParser.ZoneHour, -dateTimeParser.ZoneMinute, 0); break; case ParserTimeZone.LocalEastOfUtc: offset = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0); break; default: offset = TimeZoneInfo.Local.GetUtcOffset(dateTime); break; } long num = dateTime.Ticks - offset.Ticks; if (num < 0L || num > 3155378975999999999L) { dt = new DateTimeOffset(); return(false); } dt = new DateTimeOffset(dateTime, offset); return(true); }
internal static bool TryParseDateTimeIso(StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt) { long ticks; TimeSpan utcOffset; DateTimeParser dateTimeParser = new DateTimeParser(); if (!dateTimeParser.Parse(text.Chars, text.StartIndex, text.Length)) { dt = new DateTime(); return(false); } DateTime dateTime = DateTimeUtils.CreateDateTime(dateTimeParser); switch (dateTimeParser.Zone) { case ParserTimeZone.Utc: { dateTime = new DateTime(dateTime.Ticks, DateTimeKind.Utc); break; } case ParserTimeZone.LocalWestOfUtc: { TimeSpan timeSpan = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0); ticks = dateTime.Ticks + timeSpan.Ticks; if (ticks > DateTime.MaxValue.Ticks) { utcOffset = dateTime.GetUtcOffset(); ticks += utcOffset.Ticks; if (ticks > DateTime.MaxValue.Ticks) { ticks = DateTime.MaxValue.Ticks; } dateTime = new DateTime(ticks, DateTimeKind.Local); break; } else { dateTime = (new DateTime(ticks, DateTimeKind.Utc)).ToLocalTime(); break; } } case ParserTimeZone.LocalEastOfUtc: { TimeSpan timeSpan1 = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0); ticks = dateTime.Ticks - timeSpan1.Ticks; if (ticks < DateTime.MinValue.Ticks) { utcOffset = dateTime.GetUtcOffset(); ticks += utcOffset.Ticks; if (ticks < DateTime.MinValue.Ticks) { ticks = DateTime.MinValue.Ticks; } dateTime = new DateTime(ticks, DateTimeKind.Local); break; } else { dateTime = (new DateTime(ticks, DateTimeKind.Utc)).ToLocalTime(); break; } } } dt = DateTimeUtils.EnsureDateTime(dateTime, dateTimeZoneHandling); return(true); }