Repository navigation
feat: add DateTime.UnixNanos - #9870
lloydrichards wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 27977f2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
f131711 to
37995db
Compare
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
37995db to
4b06140
Compare
4b06140 to
27977f2
Compare
|
I recommend deferring this PR until VirtualFileSystem has a concrete consumer of nanosecond timestamps, rather than taking over the implementation now. The need is plausible, but the consumer should determine the public API. The main design concern is the amount of API being committed to before that integration exists. This adds a separate branded timestamp, numeric precision modes, a conversion error type and schemas for those errors inside the millisecond-based DateTime module. Before landing that surface, we should establish how the filesystem will use it and how it fits with Clock.currentTimeNanos and Duration. Naming and fallible conversions should also follow the existing epoch-based DateTime and branded-bigint conventions. I would leave the current implementation unchanged for now. To resume, bring a concrete filesystem call site that needs nanosecond precision, including the required range and behavior when converting to milliseconds. Then reassess the smallest useful API and reuse this PR if it is still suitable. This is a recommendation to park the takeover, not a request for a speculative rewrite. |
|
@effect-bot this might be good for protobuf too (which uses nanosecond granularity by default as well) |
what did you end up with in protobuf in the end? |
|
closing in favor of an issue #10674 as I move back to development on |
Type
Description
Another piece for the
VirtualFileSystemwork, for the attention of @fubhy.This adds
DateTime.UnixNano, a brandedbigintfor exact nanoseconds since the Unix epoch. It follows DateTime’s existing layout, with top-level functions such asunixNanoFromSecondsandunixNanoToDateTime. Existing DateTime APIs stay unchanged.Conversions reject precision loss by default. Explicit
"truncate"rounds toward zero:Values can exceed DateTime’s supported range. Conversion to
DateorDateTime.Utcchecks the original nanoseconds against that range before handling precision.Checked conversions return
ResultwithInvalidInput,OutOfRange, orPrecisionLoss.Schema.UnixNanovalidates values, with separate schemas for conversion reasons and errors.Open to suggestions on the name and API.
Related