Skip to content

fix: preserve the sign of fractional Unix timestamps - #388

Merged
superbrothers merged 1 commit into
stern:masterfrom
haramj:fix/negative-fractional-timestamps
Oct 17, 2026
Merged

superbrothers merged 1 commit into
stern:masterfrom
haramj:fix/negative-fractional-timestamps

Conversation

@haramj

@haramj haramj commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #387.

The timestamp template helpers currently turn -0.5 into 1970-01-01T00:00:00.5Z, rather than 1969-12-31T23:59:59.5Z. Apply the input's leading minus sign to the fractional nanoseconds before calling time.Unix. Checking the original string also handles -0, whose sign is lost when parsed as an integer.

Extend the existing table tests with negative integers and fractions, string and json.Number inputs, nanosecond precision, and truncation beyond nine fractional digits. The six new fractional cases fail without the parser change.

Validation (macOS arm64, Go 1.26.2):

  • make test: passed, including the pinned golangci-lint v2.12.1 and all unit tests. Run with NO_COLOR unset and TERM=xterm so the existing color tests can exercise ANSI output; CGO_ENABLED=0 for the local build environment.
  • make verify-readme and make build: passed.
  • go mod tidy: no changes to go.mod or go.sum.
  • CLI smoke test using --stdin and toTimestamp: correct results for -0.5, -1.25, and 0.5.
  • git diff --check: passed.

Release packaging and Linux CI will be validated by the PR workflow.

@superbrothers

Copy link
Copy Markdown
Member

Thank you for the PR! I will review it soon.

@superbrothers superbrothers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@superbrothers
superbrothers merged commit 6db257e into stern:master Oct 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative fractional Unix timestamps are converted to the wrong instant

2 participants