feat: add OffsetDateTime, nesting limits and uniform Marshaler dispatch
Test / test (push) Successful in 2m18s
Test / test (push) Successful in 2m18s
Assisted-by: DeepSeek V4.1 Flash
This commit is contained in:
+16
-4
@@ -11,9 +11,15 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TOML distinguishes four date-time kinds. interpres decodes an offset
|
||||
// date-time to a plain time.Time (it carries a zone), and uses the wrapper
|
||||
// types below for the local variants so callers can tell them apart.
|
||||
// TOML distinguishes four date-time kinds, and each has its own Go type:
|
||||
// OffsetDateTime for the offset kind, and the local wrappers below for the
|
||||
// three that carry no offset. A plain time.Time is accepted wherever an
|
||||
// offset date-time is, on both the encoding and the decoding side, so a
|
||||
// timestamp field does not have to name the wrapper.
|
||||
|
||||
// OffsetDateTime is a TOML offset date-time, e.g. 1979-05-27T07:32:00-07:00.
|
||||
// The embedded time.Time is the instant, with the offset the document wrote.
|
||||
type OffsetDateTime struct{ time.Time }
|
||||
|
||||
// LocalDateTime is a TOML local date-time with no offset, e.g.
|
||||
// 1979-05-27T07:32:00. The embedded time.Time is in UTC.
|
||||
@@ -27,6 +33,12 @@ type LocalDate struct{ time.Time }
|
||||
// The embedded time.Time uses the zero date.
|
||||
type LocalTime struct{ time.Time }
|
||||
|
||||
// String returns the TOML-canonical rendering of the offset date-time, e.g.
|
||||
// "1979-05-27T07:32Z" or "1979-05-27T07:32:00-07:00". The seconds appear only
|
||||
// when the value carries them, a fractional second drops its trailing zeros,
|
||||
// and an offset of zero is written "Z".
|
||||
func (odt OffsetDateTime) String() string { return offsetString(odt.Time) }
|
||||
|
||||
// String returns the TOML-canonical rendering of the local date-time, e.g.
|
||||
// "1979-05-27T07:32" or "1979-05-27T07:32:00.5" when the time carries a
|
||||
// fractional second. TOML 1.1 makes the seconds optional, so they appear only
|
||||
@@ -129,7 +141,7 @@ func parseDateTime(tok string) (any, bool) {
|
||||
norm := strings.ToUpper(tok)
|
||||
for _, layout := range offsetDateTimeLayouts {
|
||||
if t, err := time.Parse(layout, norm); err == nil {
|
||||
return t, true
|
||||
return OffsetDateTime{t}, true
|
||||
}
|
||||
}
|
||||
for _, layout := range localDateTimeLayouts {
|
||||
|
||||
Reference in New Issue
Block a user