Skip to content

Add Timestamp{P} compatibility implementation - #2

Merged
quinnj merged 1 commit into
mainfrom
jq/timestamp-compat
Sep 9, 2026
Merged

quinnj merged 1 commit into
mainfrom
jq/timestamp-compat

Conversation

@quinnj

@quinnj quinnj commented Sep 9, 2026

Copy link
Copy Markdown
Member

This adds Timestamp{P} to Durations so packages can use the type proposed for the Julia 1.14 Dates stdlib in JuliaLang/julia#62994 before it ships.

What this does

  • Durations.Timestamp is Dates.Timestamp when the Dates stdlib defines it. Durations.TIMESTAMP_FROM_DATES reports which case is active. unix2timestamp, timestamp2unix, and ISOTimestampFormat follow the same rule and are public (not exported) on Julia 1.11+.
  • Otherwise src/timestamp.jl provides a copy of the stdlib implementation: Timestamp{P} for P in Second, Millisecond, Microsecond, Nanosecond; constructors, accessors, conversions, promotion, cross-type comparison, wrapping +/-, checked rounding, adjusters, ranges, parsing, and formatting. Plain Timestamp(...) is nanoseconds.
  • On the compatibility path, loading Durations registers the n fractional-second format code and the Timestamp token order with Dates (at load time and again from __init__, since Dates globals are not persisted by precompilation).
  • Timestamp is exported alongside Duration. Version bumped to 1.1.0.

Compatibility differences (documented in the README)

  • hash agrees with == between Timestamp and DateTime and across resolutions by hashing like the equal DateTime. Date/Timestamp equal values hash differently, matching the existing Date/DateTime behavior on these Julia versions.
  • n parses and formats Timestamp and formats DateTime/Time; parsing DateTime/Time with n is unreliable before 1.14 and the README says to parse a Timestamp instead.
  • now(Timestamp) uses clock_gettime on POSIX and GetSystemTimePreciseAsFileTime on Windows, since older bundled libuv builds lack uv_clock_gettime.
  • isoyear/isoweekdate methods exist only where Dates defines them (1.13+). Negative-year string parsing needs the 1.12 Dates parser.

Validation

  • test/timestamps.jl is the stdlib test file from the PR, adapted with the gates above. It runs against whichever implementation is active.
  • Passed locally: Julia 1.10.11, 1.11.9, 1.12.6 (compat path via Pkg.test), a 1.14-dev build without the PR (compat path), and the same build with the PR's Dates checkout on the load path (alias path; confirms Durations.Timestamp === Dates.Timestamp).
  • The trim workload now constructs, adds, subtracts, rounds, converts, and hashes a Timestamp; it compiles and runs under --trim=safe on 1.12.6 locally.
  • Not verified locally: Windows (the GetSystemTimePreciseAsFileTime path) and nightly.

🤖 Generated with Claude Code

Provide `Timestamp{P}`, the Int64 Unix-epoch instant type proposed for the
Julia 1.14 Dates stdlib in JuliaLang/julia#62994, so packages can depend on it
before that release. When `Dates.Timestamp` exists, `Durations.Timestamp` is
the stdlib type; otherwise `src/timestamp.jl` supplies the same constructors,
accessors, conversions, promotion, comparison, arithmetic, checked rounding,
adjusters, ranges, parsing, and formatting, and registers the `n`
fractional-second format code with Dates at load time.

Differences on the compatibility path are documented in the README: the
`Timestamp`/`DateTime` hash agreement is kept by hashing like the equal
`DateTime`, `Date` hashes stay as they are in those Julia versions, `now`
reads the clock through `clock_gettime`/`GetSystemTimePreciseAsFileTime`,
and `isoyear`/`isoweekdate` follow the stdlib's availability.

The test suite runs the stdlib's `timestamps.jl` against whichever
implementation is active, and the trim workload now exercises `Timestamp`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@quinnj
quinnj merged commit 2ef27b2 into main Sep 9, 2026
9 checks 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.

1 participant