Skip to content

Commit

Permalink
chore: Update chrono crate and avoid newly deprecated function (#868)
Browse files Browse the repository at this point in the history
Change calls to DataTime::from_utc() to DateTime::from_naive_utc_and_offset:
Deprecated since 0.4.27: Use DateTime::from_naive_utc_and_offset instead.

Co-authored-by: Harrison Kaiser <[email protected]>
  • Loading branch information
harrisonkaiser and Harrison Kaiser authored Oct 28, 2023
1 parent 55dff09 commit 1ae170a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ percent-encoding = {version = "2.2", optional = true}
# used in filesizeformat filter
humansize = {version = "2.1", optional = true}
# used in date format filter
chrono = {version = "0.4.23", optional = true, default-features = false, features = ["std", "clock"]}
chrono = {version = "0.4.27", optional = true, default-features = false, features = ["std", "clock"]}
# used in date format filter
chrono-tz = {version = "0.8", optional = true}
# used in get_random function
Expand Down
10 changes: 6 additions & 4 deletions src/builtins/filters/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn date(value: &Value, args: &HashMap<String, Value>) -> Result<Value> {
None => val.format_localized(&format, locale),
},
Err(_) => match s.parse::<NaiveDateTime>() {
Ok(val) => DateTime::<Utc>::from_utc(val, Utc)
Ok(val) => DateTime::<Utc>::from_naive_utc_and_offset(val, Utc)
.format_localized(&format, locale),
Err(_) => {
return Err(Error::msg(format!(
Expand All @@ -142,7 +142,7 @@ pub fn date(value: &Value, args: &HashMap<String, Value>) -> Result<Value> {
}
} else {
match NaiveDate::parse_from_str(s, "%Y-%m-%d") {
Ok(val) => DateTime::<Utc>::from_utc(
Ok(val) => DateTime::<Utc>::from_naive_utc_and_offset(
val.and_hms_opt(0, 0, 0).expect(
"out of bound should not appear, as we set the time to zero",
),
Expand Down Expand Up @@ -190,7 +190,9 @@ pub fn date(value: &Value, args: &HashMap<String, Value>) -> Result<Value> {
None => val.format(&format),
},
Err(_) => match s.parse::<NaiveDateTime>() {
Ok(val) => DateTime::<Utc>::from_utc(val, Utc).format(&format),
Ok(val) => {
DateTime::<Utc>::from_naive_utc_and_offset(val, Utc).format(&format)
}
Err(_) => {
return Err(Error::msg(format!(
"Error parsing `{:?}` as rfc3339 date or naive datetime",
Expand All @@ -201,7 +203,7 @@ pub fn date(value: &Value, args: &HashMap<String, Value>) -> Result<Value> {
}
} else {
match NaiveDate::parse_from_str(s, "%Y-%m-%d") {
Ok(val) => DateTime::<Utc>::from_utc(
Ok(val) => DateTime::<Utc>::from_naive_utc_and_offset(
val.and_hms_opt(0, 0, 0)
.expect("out of bound should not appear, as we set the time to zero"),
Utc,
Expand Down

0 comments on commit 1ae170a

Please sign in to comment.