Skip to content

Commit

Permalink
Replace deprecated calls to chrono
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Apr 6, 2024
1 parent 6739bd1 commit 2fe0bd0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on: [push, pull_request]

env:
minrust: 1.57.0
minrust: 1.61.0

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- cron: '0 2 * * *'

env:
minrust: 1.57.0
minrust: 1.61.0

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"
license = "MIT"
keywords = ["serde", "serialization", "deserialization"]
edition = "2021"
rust-version = "1.57"
rust-version = "1.61"
repository = "https://github.com/iddm/serde-aux"
documentation = "https://docs.rs/serde-aux"

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The minimal rust version the library supports:
- Up to version `3.0.0` (excluding) - rustc `1.36`.
- Since `3.0.0` - rustc `1.56`.
- Since `4.3.0` - rustc `1.57`.
- Since `4.5.1` - rustc `1.61`.

## License
This project is [licensed under the MIT license](https://github.com/iddm/serde-aux/blob/master/LICENSE).
19 changes: 5 additions & 14 deletions src/field_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,9 @@ where
{
use chrono::prelude::*;

let number = deserialize_number_from_string::<i64, D>(deserializer)?;
let seconds = number / 1000;
let millis = (number % 1000) as u32;
let nanos = millis * 1_000_000;

Ok(Utc.from_utc_datetime(
&NaiveDateTime::from_timestamp_opt(seconds, nanos)
.ok_or_else(|| D::Error::custom("Couldn't parse the timestamp"))?,
))
let millis = deserialize_number_from_string::<i64, D>(deserializer)?;
DateTime::<Utc>::from_timestamp_millis(millis)
.ok_or_else(|| D::Error::custom("Couldn't parse the timestamp"))
}

/// Deserializes a `chrono::DateTime<Utc>` from a seconds time stamp.
Expand Down Expand Up @@ -247,11 +241,8 @@ where
use chrono::prelude::*;

let seconds = deserialize_number_from_string::<i64, D>(deserializer)?;

Ok(Utc.from_utc_datetime(
&NaiveDateTime::from_timestamp_opt(seconds, 0)
.ok_or_else(|| D::Error::custom("Couldn't parse the timestamp"))?,
))
DateTime::<Utc>::from_timestamp(seconds, 0)
.ok_or_else(|| D::Error::custom("Couldn't parse the timestamp"))
}

/// Deserializes a number from string or a number.
Expand Down

0 comments on commit 2fe0bd0

Please sign in to comment.