Skip to content

Commit 7aa45d6

Browse files
committed
chore: update time api
1 parent 18d08e5 commit 7aa45d6

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

examples/helper_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::error::Error;
33
use handlebars::{Handlebars, JsonRender, handlebars_helper};
44
use serde_json::{Value, json};
55
use time::OffsetDateTime;
6-
use time::format_description::parse;
6+
use time::format_description::parse_borrowed;
77

88
// define a helper using helper
99
// a date format helper accept an `OffsetDateTime` as parameter
10-
handlebars_helper!(date: |dt: OffsetDateTime| dt.format(&parse("[year]-[month]-[day]").unwrap()).unwrap());
10+
handlebars_helper!(date: |dt: OffsetDateTime| dt.format(&parse_borrowed::<1>("[year]-[month]-[day]").unwrap()).unwrap());
1111

1212
// a helper returns number of provided parameters
1313
handlebars_helper!(nargs: |*args| args.len());
@@ -21,7 +21,7 @@ handlebars_helper!(isdefined: |v: Value| !v.is_null());
2121

2222
// a helper provides format
2323
handlebars_helper!(date2: |dt: OffsetDateTime, {fmt:str = "[year]-[month]-[day]"}|
24-
dt.format(&parse(fmt).unwrap()).unwrap()
24+
dt.format(&parse_borrowed::<1>(fmt).unwrap()).unwrap()
2525
);
2626

2727
fn main() -> Result<(), Box<dyn Error>> {

tests/helper_macro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate serde_json;
55

66
use handlebars::Handlebars;
77
use time::OffsetDateTime;
8-
use time::format_description::{parse, well_known::Rfc2822};
8+
use time::format_description::{parse_borrowed, well_known::Rfc2822};
99

1010
handlebars_helper!(lower: |s: str| s.to_lowercase());
1111
handlebars_helper!(upper: |s: str| s.to_uppercase());
@@ -16,7 +16,7 @@ handlebars_helper!(nargs: |*args| args.len());
1616
handlebars_helper!(has_a: |{a:i64 = 99}, **kwargs|
1717
format!("{}, {}", a, kwargs.contains_key("a")));
1818
handlebars_helper!(tag: |t: str| format!("<{}>", t));
19-
handlebars_helper!(date: |dt: OffsetDateTime| dt.format(&parse("[year]-[month]-[day]").unwrap()).unwrap());
19+
handlebars_helper!(date: |dt: OffsetDateTime| dt.format(&parse_borrowed::<1>("[year]-[month]-[day]").unwrap()).unwrap());
2020

2121
#[test]
2222
fn test_macro_helper() {

0 commit comments

Comments
 (0)