a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky

docs(time-ms): explain better why this package exists

mary.my.id a2b0ca2d f8d16167

verified
+14 -2
+14 -2
packages/misc/time-ms/README.md
··· 1 1 # @atcute/time-ms 2 2 3 - high precision system time, returns in microseconds (messed up the package name!) 3 + high-precision absolute system time in microseconds (messed up the package name!) 4 4 5 5 ```sh 6 6 npm install @atcute/time-ms 7 7 ``` 8 8 9 + JavaScript doesn't provide a built-in way to get the current wall-clock time with microsecond 10 + precision. `Date.now()` only goes to milliseconds, and the high-resolution alternatives 11 + (`performance.now()`, `process.hrtime()`) are monotonic clocks — great for measuring durations, but 12 + they don't tell you the actual time. 13 + 14 + this package calls the platform's real-time clock directly via native bindings or FFI 15 + (`clock_gettime(CLOCK_REALTIME)` on Unix, `GetSystemTimePreciseAsFileTime` on Windows) to return the 16 + current time as microseconds since the Unix epoch. falls back to `Date.now() * 1000` when native 17 + access is unavailable. 18 + 9 19 ## usage 10 20 11 21 ```ts 12 - import { now } from '@atcute/time-ms'; 22 + import { now, hasNative } from '@atcute/time-ms'; 13 23 14 24 const timestamp = now(); 15 25 // ^ 1766739339478426 16 26 // returns microseconds since unix epoch 27 + 28 + hasNative; // whether the native module is available for the current runtime 17 29 ```