Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros

◆ FormatCustomized()

static StringBuilder System.DateTimeFormat.FormatCustomized ( DateTime dateTime,
ReadOnlySpan< char > format,
DateTimeFormatInfo dtfi,
TimeSpan offset,
StringBuilder result )
inlinestaticprivate

Definition at line 187 of file DateTimeFormat.cs.

188 {
189 Calendar calendar = dtfi.Calendar;
190 bool flag = false;
191 if (result == null)
192 {
193 flag = true;
194 result = StringBuilderCache.Acquire();
195 }
196 bool flag2 = calendar.ID == CalendarId.HEBREW;
197 bool flag3 = calendar.ID == CalendarId.JAPAN;
198 bool timeOnly = true;
199 int num;
200 for (int i = 0; i < format.Length; i += num)
201 {
202 char c = format[i];
203 switch (c)
204 {
205 case 'g':
206 num = ParseRepeatPattern(format, i, c);
207 result.Append(dtfi.GetEraName(calendar.GetEra(dateTime)));
208 break;
209 case 'h':
210 {
211 num = ParseRepeatPattern(format, i, c);
212 int num3 = dateTime.Hour % 12;
213 if (num3 == 0)
214 {
215 num3 = 12;
216 }
217 FormatDigits(result, num3, num);
218 break;
219 }
220 case 'H':
221 num = ParseRepeatPattern(format, i, c);
222 FormatDigits(result, dateTime.Hour, num);
223 break;
224 case 'm':
225 num = ParseRepeatPattern(format, i, c);
226 FormatDigits(result, dateTime.Minute, num);
227 break;
228 case 's':
229 num = ParseRepeatPattern(format, i, c);
230 FormatDigits(result, dateTime.Second, num);
231 break;
232 case 'F':
233 case 'f':
234 num = ParseRepeatPattern(format, i, c);
235 if (num <= 7)
236 {
237 long num4 = dateTime.Ticks % 10000000;
238 num4 /= (long)Math.Pow(10.0, 7 - num);
239 if (c == 'f')
240 {
241 result.AppendSpanFormattable((int)num4, fixedNumberFormats[num - 1], CultureInfo.InvariantCulture);
242 break;
243 }
244 int num5 = num;
245 while (num5 > 0 && num4 % 10 == 0L)
246 {
247 num4 /= 10;
248 num5--;
249 }
250 if (num5 > 0)
251 {
252 result.AppendSpanFormattable((int)num4, fixedNumberFormats[num5 - 1], CultureInfo.InvariantCulture);
253 }
254 else if (result.Length > 0 && result[result.Length - 1] == '.')
255 {
256 result.Remove(result.Length - 1, 1);
257 }
258 break;
259 }
260 if (flag)
261 {
263 }
264 throw new FormatException(SR.Format_InvalidString);
265 case 't':
266 num = ParseRepeatPattern(format, i, c);
267 if (num == 1)
268 {
269 if (dateTime.Hour < 12)
270 {
271 if (dtfi.AMDesignator.Length >= 1)
272 {
273 result.Append(dtfi.AMDesignator[0]);
274 }
275 }
276 else if (dtfi.PMDesignator.Length >= 1)
277 {
278 result.Append(dtfi.PMDesignator[0]);
279 }
280 }
281 else
282 {
283 result.Append((dateTime.Hour < 12) ? dtfi.AMDesignator : dtfi.PMDesignator);
284 }
285 break;
286 case 'd':
287 num = ParseRepeatPattern(format, i, c);
288 if (num <= 2)
289 {
290 int dayOfMonth = calendar.GetDayOfMonth(dateTime);
291 if (flag2)
292 {
294 }
295 else
296 {
297 FormatDigits(result, dayOfMonth, num);
298 }
299 }
300 else
301 {
302 int dayOfWeek = (int)calendar.GetDayOfWeek(dateTime);
303 result.Append(FormatDayOfWeek(dayOfWeek, num, dtfi));
304 }
305 timeOnly = false;
306 break;
307 case 'M':
308 {
309 num = ParseRepeatPattern(format, i, c);
310 int month = calendar.GetMonth(dateTime);
311 if (num <= 2)
312 {
313 if (flag2)
314 {
315 HebrewFormatDigits(result, month);
316 }
317 else
318 {
319 FormatDigits(result, month, num);
320 }
321 }
322 else if (flag2)
323 {
324 result.Append(FormatHebrewMonthName(dateTime, month, num, dtfi));
325 }
326 else if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0)
327 {
328 result.Append(dtfi.InternalGetMonthName(month, IsUseGenitiveForm(format, i, num, 'd') ? MonthNameStyles.Genitive : MonthNameStyles.Regular, num == 3));
329 }
330 else
331 {
332 result.Append(FormatMonth(month, num, dtfi));
333 }
334 timeOnly = false;
335 break;
336 }
337 case 'y':
338 {
339 int year = calendar.GetYear(dateTime);
340 num = ParseRepeatPattern(format, i, c);
341 if (flag3 && !LocalAppContextSwitches.FormatJapaneseFirstYearAsANumber && year == 1 && ((i + num < format.Length && format[i + num] == '年') || (i + num < format.Length - 1 && format[i + num] == '\'' && format[i + num + 1] == '年')))
342 {
343 result.Append("元"[0]);
344 }
345 else if (dtfi.HasForceTwoDigitYears)
346 {
347 FormatDigits(result, year, (num <= 2) ? num : 2);
348 }
349 else if (calendar.ID == CalendarId.HEBREW)
350 {
351 HebrewFormatDigits(result, year);
352 }
353 else if (num <= 2)
354 {
355 FormatDigits(result, year % 100, num);
356 }
357 else if (num <= 16)
358 {
360 }
361 else
362 {
363 result.Append(year.ToString("D" + num.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture));
364 }
365 timeOnly = false;
366 break;
367 }
368 case 'z':
369 num = ParseRepeatPattern(format, i, c);
371 break;
372 case 'K':
373 num = 1;
375 break;
376 case ':':
377 result.Append(dtfi.TimeSeparator);
378 num = 1;
379 break;
380 case '/':
381 result.Append(dtfi.DateSeparator);
382 num = 1;
383 break;
384 case '"':
385 case '\'':
386 num = ParseQuoteString(format, i, result);
387 break;
388 case '%':
389 {
390 int num2 = ParseNextChar(format, i);
391 if (num2 >= 0 && num2 != 37)
392 {
393 char reference = (char)num2;
395 num = 2;
396 break;
397 }
398 if (flag)
399 {
401 }
402 throw new FormatException(SR.Format_InvalidString);
403 }
404 case '\\':
405 {
406 int num2 = ParseNextChar(format, i);
407 if (num2 >= 0)
408 {
409 result.Append((char)num2);
410 num = 2;
411 break;
412 }
413 if (flag)
414 {
416 }
417 throw new FormatException(SR.Format_InvalidString);
418 }
419 default:
420 result.Append(c);
421 num = 1;
422 break;
423 }
424 }
425 return result;
426 }
static int ParseNextChar(ReadOnlySpan< char > format, int pos)
static string FormatMonth(int month, int repeatCount, DateTimeFormatInfo dtfi)
static string FormatHebrewMonthName(DateTime time, int month, int repeatCount, DateTimeFormatInfo dtfi)
static bool IsUseGenitiveForm(ReadOnlySpan< char > format, int index, int tokenLen, char patternToMatch)
static StringBuilder FormatCustomized(DateTime dateTime, ReadOnlySpan< char > format, DateTimeFormatInfo dtfi, TimeSpan offset, StringBuilder result)
static int ParseRepeatPattern(ReadOnlySpan< char > format, int pos, char patternChar)
static string FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
static void FormatCustomizedTimeZone(DateTime dateTime, TimeSpan offset, int tokenLen, bool timeOnly, StringBuilder result)
static int ParseQuoteString(ReadOnlySpan< char > format, int pos, StringBuilder result)
static void FormatDigits(StringBuilder outputBuffer, int value, int len)
static string[] fixedNumberFormats
static void HebrewFormatDigits(StringBuilder outputBuffer, int digits)
static void FormatCustomizedRoundripTimeZone(DateTime dateTime, TimeSpan offset, StringBuilder result)
DayOfWeek GetDayOfWeek(DateTime time)
int GetYear(DateTime time)
int GetDayOfMonth(DateTime time)
virtual CalendarId ID
Definition Calendar.cs:19
int GetMonth(DateTime time)
int GetEra(DateTime time)
static CultureInfo InvariantCulture
static void Release(StringBuilder sb)
static StringBuilder Acquire(int capacity=16)
StringBuilder Remove(int startIndex, int length)
StringBuilder Append(char value, int repeatCount)

References System.Text.StringBuilderCache.Acquire(), System.Text.StringBuilder.Append(), System.DateTimeFormat.fixedNumberFormats, System.format, System.SR.Format_InvalidString, System.DateTimeFormat.FormatCustomized(), System.DateTimeFormat.FormatCustomizedRoundripTimeZone(), System.DateTimeFormat.FormatCustomizedTimeZone(), System.DateTimeFormat.FormatDayOfWeek(), System.DateTimeFormat.FormatDigits(), System.DateTimeFormat.FormatHebrewMonthName(), System.LocalAppContextSwitches.FormatJapaneseFirstYearAsANumber, System.DateTimeFormat.FormatMonth(), System.Globalization.Calendar.GetDayOfMonth(), System.Globalization.Calendar.GetDayOfWeek(), System.Globalization.Calendar.GetEra(), System.Globalization.Calendar.GetMonth(), System.Globalization.Calendar.GetYear(), System.DateTimeFormat.HebrewFormatDigits(), System.Globalization.Calendar.ID, System.Globalization.CultureInfo.InvariantCulture, System.DateTimeFormat.IsUseGenitiveForm(), System.L, System.Text.StringBuilder.Length, System.offset, System.DateTimeFormat.ParseNextChar(), System.DateTimeFormat.ParseQuoteString(), System.DateTimeFormat.ParseRepeatPattern(), System.Math.Pow(), System.Text.StringBuilderCache.Release(), System.Text.StringBuilder.Remove(), and System.year.

Referenced by System.DateTimeFormat.FormatCustomized(), and System.DateTimeFormat.FormatStringBuilder().