Repository navigation
Add Timestamp{P} compatibility implementation - #2
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.TimestampisDates.Timestampwhen the Dates stdlib defines it.Durations.TIMESTAMP_FROM_DATESreports which case is active.unix2timestamp,timestamp2unix, andISOTimestampFormatfollow the same rule and arepublic(not exported) on Julia 1.11+.src/timestamp.jlprovides a copy of the stdlib implementation:Timestamp{P}forPinSecond,Millisecond,Microsecond,Nanosecond; constructors, accessors, conversions, promotion, cross-type comparison, wrapping+/-, checked rounding, adjusters, ranges, parsing, and formatting. PlainTimestamp(...)is nanoseconds.nfractional-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).Timestampis exported alongsideDuration. Version bumped to 1.1.0.Compatibility differences (documented in the README)
hashagrees with==betweenTimestampandDateTimeand across resolutions by hashing like the equalDateTime.Date/Timestampequal values hash differently, matching the existingDate/DateTimebehavior on these Julia versions.nparses and formatsTimestampand formatsDateTime/Time; parsingDateTime/Timewithnis unreliable before 1.14 and the README says to parse aTimestampinstead.now(Timestamp)usesclock_gettimeon POSIX andGetSystemTimePreciseAsFileTimeon Windows, since older bundled libuv builds lackuv_clock_gettime.isoyear/isoweekdatemethods exist only where Dates defines them (1.13+). Negative-year string parsing needs the 1.12 Dates parser.Validation
test/timestamps.jlis the stdlib test file from the PR, adapted with the gates above. It runs against whichever implementation is active.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; confirmsDurations.Timestamp === Dates.Timestamp).Timestamp; it compiles and runs under--trim=safeon 1.12.6 locally.GetSystemTimePreciseAsFileTimepath) and nightly.🤖 Generated with Claude Code