Add now for current datetime

This commit is contained in:
Tiffany Bennett 2016-08-20 13:28:52 -04:00
parent af9d4d57ee
commit 6582ff4783
2 changed files with 5 additions and 0 deletions

View file

@ -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))
}

View file

@ -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) =>