time-rs / time

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

Add from_unix_timestamp_millis/_micros for convenience #631

Closed alekspickle closed 7 months ago

alekspickle commented 9 months ago

It would be much more convenient to have these than parsing text to offset, calculating stuff just for it to be serialized again.

Tests, docs and clippy seem to pass locally(I guess it's configured different in CI). Other than that - feel free to edit or benchmark, but I doubt it will seriously impact anything: in the end it just uses different remaining digits

I would really want to merge it though since doing stuff like:

let parsed_unix_ts = format!("{}000", value.__realtime_timestamp)
            .parse::<i128>()
            .expect("Failed to parse timestamp");
        let timestamp = OffsetDateTime::from_unix_timestamp_nanos(parsed_unix_ts)

is pure evil

codecov[bot] commented 9 months ago

Codecov Report

Merging #631 (99c17a3) into main (72f03e0) will decrease coverage by 0.5%. The diff coverage is 0.0%.

@@           Coverage Diff           @@
##            main    #631     +/-   ##
=======================================
- Coverage   98.1%   97.6%   -0.5%     
=======================================
  Files         80      80             
  Lines       9318    9370     +52     
=======================================
  Hits        9144    9144             
- Misses       174     226     +52     
Files Coverage Δ
time/src/offset_date_time.rs 96.0% <0.0%> (-4.0%) :arrow_down:
time/src/date_time.rs 88.8% <0.0%> (-5.4%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

jhpratt commented 9 months ago

I would really want to merge it though since doing stuff like:

let parsed_unix_ts = format!("{}000", value.__realtime_timestamp)
            .parse::<i128>()
            .expect("Failed to parse timestamp");
        let timestamp = OffsetDateTime::from_unix_timestamp_nanos(parsed_unix_ts)

What makes you think that's necessary? You can multiply the value by 1,000 or 1,000,000 before passing it to OffsetDateTime::from_unix_timestamp_nanos.

github-actions[bot] commented 8 months ago

This pull request has not had any activity recently. It will be closed without further activity.