time-rs / time

The most used Rust library for date and time handling.
https://time-rs.github.io
Apache License 2.0
1.11k stars 278 forks source link

no millis? #539

Closed hp8wvvvgnj6asjm7 closed 1 year ago

hp8wvvvgnj6asjm7 commented 1 year ago

Am I missing something here?

println!("{:?}", OffsetDateTime::now_utc().unix_timestamp_nanos());
...? micros
...? millis
println!("{:?}", OffsetDateTime::now_utc().unix_timestamp());
jhpratt commented 1 year ago

Multiply it by 1000 or 1,000,000 and use unix_timestamp_nanos. The only reason there are even two methods is because they accept different types.

hp8wvvvgnj6asjm7 commented 1 year ago

https://doc.rust-lang.org/nightly/core/time/struct.Duration.html#implementations

https://github.com/rust-lang/rust/issues/57391

why would you not add this for the same ergonomic reasons?

jhpratt commented 1 year ago

I'm not sure I follow. A Duration and an OffsetDateTime are two completely different types with zero overlap in functionality.

AshfordN commented 1 year ago

On this note, I think it is important to explicitly state, in the docs, that the *_unix_timestamp() functions operate on seconds, as opposed to some other unit, such as milliseconds. I know it should be understood or expected that all Unix timestamps are in second, but this omission could potentially lead to confusion and ambiguity, since some external APIs, such as Javascript's Date API (in the context of a WASM module), returns millisecond timestamps.

jhpratt commented 1 year ago

@AshfordN The Unix timestamp is, by definition, in seconds.