Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ParseJsonDateInDefaultFormat()

static DateTime System.Runtime.Serialization.Json.JsonReaderDelegator.ParseJsonDateInDefaultFormat ( string originalDateTimeValue)
inlinestaticpackage

Definition at line 168 of file JsonReaderDelegator.cs.

169 {
170 string text = (string.IsNullOrEmpty(originalDateTimeValue) ? originalDateTimeValue : originalDateTimeValue.Trim());
171 if (string.IsNullOrEmpty(text) || !text.StartsWith("/Date(", StringComparison.Ordinal) || !text.EndsWith(")/", StringComparison.Ordinal))
172 {
173 throw new FormatException(System.SR.Format(System.SR.JsonInvalidDateTimeString, originalDateTimeValue, "\\/Date(", ")\\/"));
174 }
175 string text2 = text.Substring(6, text.Length - 8);
177 int num = text2.IndexOf('+', 1);
178 if (num == -1)
179 {
180 num = text2.IndexOf('-', 1);
181 }
182 if (num != -1)
183 {
185 text2 = text2.Substring(0, num);
186 }
187 long num2;
188 try
189 {
190 num2 = long.Parse(text2, CultureInfo.InvariantCulture);
191 }
193 {
195 }
196 catch (FormatException exception2)
197 {
199 }
200 catch (OverflowException exception3)
201 {
203 }
204 long ticks = num2 * 10000 + JsonGlobals.unixEpochTicks;
205 try
206 {
207 DateTime dateTime = new DateTime(ticks, DateTimeKind.Utc);
208 return dateTimeKind switch
209 {
210 DateTimeKind.Local => dateTime.ToLocalTime(),
211 DateTimeKind.Unspecified => DateTime.SpecifyKind(dateTime.ToLocalTime(), DateTimeKind.Unspecified),
212 _ => dateTime,
213 };
214 }
216 {
218 }
219 }
static CultureInfo InvariantCulture
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string JsonInvalidDateTimeString
Definition SR.cs:536
Definition SR.cs:7
static XmlException CreateConversionException(string type, Exception exception)

References System.Xml.XmlExceptionHelper.CreateConversionException(), System.DateTime, System.Runtime.Serialization.Dictionary, System.exception, System.SR.Format(), System.Globalization.CultureInfo.InvariantCulture, System.SR.JsonInvalidDateTimeString, System.DateTime.SpecifyKind(), System.text, and System.Runtime.Serialization.Json.JsonGlobals.unixEpochTicks.

Referenced by System.Runtime.Serialization.Json.JsonReaderDelegator.ParseJsonDate().