44 *
55 * The formatters operate on a plain `DateInfo` (wall-clock fields), which the
66 * Temporal types expose directly (`d.year`, `d.hour`, `d.dayOfWeek % 7`, ...),
7- * so no JS-Date intermediate is needed. `parseRaw` still leans on the JS `Date`
8- * built-in for .NET-compatible lenient parsing (Temporal has only strict ISO
9- * parsers); it returns wall-clock fields the callers turn into Temporal values.
7+ * so no JS-Date intermediate is needed there.
8+ *
9+ * Parsing is the exception. .NET accepts far more than ISO 8601 ("12/30/2009",
10+ * "June 15, 2009 1:45 PM"), and the JS `Date` built-in is the only lenient date
11+ * parser the platform offers — Temporal's `from` is strict ISO and rejects all of
12+ * it. So `parseRaw` uses `Date` as a parsing engine and returns the instant it
13+ * resolved, which callers convert into the Temporal value they need. That instant
14+ * is only millisecond-precise, hence `subMillisecondTicks`: the finer digits are
15+ * read straight off the input, because `Date` has already discarded them.
1016 *
1117 * This is a port of the equivalent logic in Date.ts / DateOffset.ts, kept
1218 * separate so the Temporal modules do not depend on the JS-Date representation.
@@ -378,16 +384,6 @@ export function dateToString_R(info: DateInfo): string {
378384 + padWithZeros ( info . second , 2 ) + " GMT" ;
379385}
380386
381- // Sortable ISO 8601, no timezone: "2009-06-15T13:45:30"
382- export function dateToString_s ( info : DateInfo ) : string {
383- return padWithZeros ( info . year , 4 ) + "-"
384- + padWithZeros ( info . month , 2 ) + "-"
385- + padWithZeros ( info . day , 2 ) + "T"
386- + padWithZeros ( info . hour , 2 ) + ":"
387- + padWithZeros ( info . minute , 2 ) + ":"
388- + padWithZeros ( info . second , 2 ) ;
389- }
390-
391387// Universal sortable: "2009-06-15 13:45:30Z". `info` must already be UTC.
392388export function dateToString_u ( info : DateInfo ) : string {
393389 return padWithZeros ( info . year , 4 ) + "-"
@@ -408,29 +404,18 @@ export function dateToString_Y(info: DateInfo): string {
408404 return info . year + " " + longMonths [ info . month - 1 ] ;
409405}
410406
411- // Round-trip "O"/"o": "2009-06-15T13:45:30.1234567" + an offset suffix (a bare
412- // "Z" for UTC, an offset like "+01:00", or "" when unspecified). .NET prints all
413- // 7 tick digits here — that is what makes the format round-trip.
414- export function dateToString_O ( info : DateInfo , suffix : string ) : string {
415- return padWithZeros ( info . year , 4 ) + "-"
416- + padWithZeros ( info . month , 2 ) + "-"
417- + padWithZeros ( info . day , 2 ) + "T"
418- + padWithZeros ( info . hour , 2 ) + ":"
419- + padWithZeros ( info . minute , 2 ) + ":"
420- + padWithZeros ( info . second , 2 ) + "."
421- + fractionDigits ( info ) + suffix ;
422- }
423-
424407// Everything a standard format specifier needs beyond the wall-clock fields.
425408// DateTime and DateTimeOffset differ only in these, so they share the table below.
426409// Everything past `info` is a thunk: most specifiers need none of them, and each
427410// costs a time-zone conversion.
428411export interface FormatContext {
429412 info : DateInfo ;
430413 utcInfo : ( ) => DateInfo ;
431- // Trails the round-trip "O": "Z" for UTC, an offset like "+01:00", or "" when
432- // the value carries no zone information at all.
433- roundTripSuffix : ( ) => string ;
414+ // "O"/"o" and "s" are ISO 8601, which Temporal renders itself — and renders
415+ // tick-exactly — so the owning module supplies them rather than this file
416+ // reassembling the fields by hand.
417+ roundTrip : ( ) => string ;
418+ sortable : ( ) => string ;
434419 // Trails the no-format rendering. A DateTimeOffset shows its offset there; a
435420 // DateTime has none to show.
436421 defaultSuffix : string ;
@@ -457,9 +442,9 @@ export function dateToString(ctx: FormatContext, format?: string): string {
457442 case "G" : return dateToString_d ( info ) + " " + dateToString_T ( info ) ;
458443 case "g" : return dateToString_d ( info ) + " " + dateToString_t ( info ) ;
459444 case "M" : case "m" : return dateToString_M ( info ) ;
460- case "O" : case "o" : return dateToString_O ( info , ctx . roundTripSuffix ( ) ) ;
445+ case "O" : case "o" : return ctx . roundTrip ( ) ;
461446 case "R" : case "r" : return dateToString_R ( ctx . utcInfo ( ) ) ;
462- case "s" : return dateToString_s ( info ) ;
447+ case "s" : return ctx . sortable ( ) ;
463448 case "T" : return dateToString_T ( info ) ;
464449 case "t" : return dateToString_t ( info ) ;
465450 case "u" : return dateToString_u ( ctx . utcInfo ( ) ) ;
0 commit comments