Repository navigation
fix: preserve an explicit year zero in TimestampFlag - #2458
Conversation
|
There was a problem hiding this comment.
Thanks, the fix looks correct. The three new cases fail on main and pass here, and yearless layouts such as "01-02" and "15:04" still default to the current year/date.
I pushed 029b760, which merges layoutHasDate and layoutHasYear into one probe, since both round-tripped the same reference time with different reference years (2 and 2001):
Lines 130 to 139 in 029b760
An omitted year always parses as year 0, and "06" never parses as 0 (00 is 2000), so p.Year() != 0 is enough to tell whether the layout carries a year.
layoutHasDate and layoutHasYear round-tripped the same reference time through the layout, only with different reference years (2 and 2001). An omitted year always parses as year 0, and a two-digit "06" year never parses as 0, so one probe can report both whether the layout carries a year and whether it carries a month/day. Replace both helpers with layoutFields. Reference: 37ad84c ("fix: preserve explicit year zero in timestamp flags") Reference: e8c2eb5 ("Fix a year-less timestamp layout losing January 1") Assisted-by: claude:claude-opus-5-5 Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
d83a84d to
029b760
Compare
What type of PR is this?
What this PR does / why we need it:
TimestampFlagreplaces a parsed year of zero with the current year even when the layout and input explicitly contain0000. For example,--time 0000-02-29T12:34:56Zwithtime.RFC3339becomes March 1 of the current non-leap year instead of preserving the supplied timestamp.Distinguish an omitted year from an explicit zero year by probing the matched layout, just as the existing date-presence helper does. Preserve yearless/time-only defaulting. Add CLI-level regressions for RFC3339, a full date, and a year-plus-time layout.
Which issue(s) this PR fixes:
No existing issue found. Searched timestamp/year issues and open/closed PRs, including #2427 and #2450; those address layouts without a year rather than an explicitly supplied year zero.
Testing
go test ./...passed, including the existing yearless and time-only timezone cases.go vet ./...passed.make v3diffpassed (no public API change).gofmt. Fullmake all/ gfmrun documentation checks were not run.Release Notes