mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
Add now
for current datetime
This commit is contained in:
parent
af9d4d57ee
commit
6582ff4783
2 changed files with 5 additions and 0 deletions
|
@ -200,3 +200,7 @@ pub fn to_duration(num: &Number) -> Result<Duration, String> {
|
|||
let num: Option<i64> = (&(&num.0.get_num() / &num.0.get_den())).into();
|
||||
Ok(Duration::seconds(num.unwrap()))
|
||||
}
|
||||
|
||||
pub fn now() -> DateTime<FixedOffset> {
|
||||
UTC::now().with_timezone(&FixedOffset::east(0))
|
||||
}
|
||||
|
|
|
@ -280,6 +280,7 @@ impl Context {
|
|||
}
|
||||
|
||||
match *expr {
|
||||
Expr::Unit(ref name) if name == "now" => Ok(Value::DateTime(date::now())),
|
||||
Expr::Unit(ref name) => self.lookup(name).ok_or(format!("Unknown unit {}", name)).map(Value::Number),
|
||||
Expr::Quote(ref name) => Ok(Value::Number(Number::one_unit(Rc::new(name.clone())))),
|
||||
Expr::Const(ref num, ref frac, ref exp) =>
|
||||
|
|
Loading…
Reference in a new issue