From 752817ae74607ca23ec0aad51824ddca66faa7a8 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> Date: Tue, 23 May 2023 10:41:20 +0200 Subject: Add support for date & time handling (#435) --- src/eval/methods.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/eval/methods.rs') diff --git a/src/eval/methods.rs b/src/eval/methods.rs index 8d042a5c..42084543 100644 --- a/src/eval/methods.rs +++ b/src/eval/methods.rs @@ -4,6 +4,7 @@ use ecow::EcoString; use super::{Args, Str, Value, Vm}; use crate::diag::{At, SourceResult}; +use crate::eval::Datetime; use crate::model::{Location, Selector}; use crate::syntax::Span; @@ -185,6 +186,30 @@ pub fn call( } _ => return missing(), } + } else if let Some(&datetime) = dynamic.downcast::() { + match method { + "display" => datetime.display(args.eat()?).at(args.span)?.into(), + "year" => { + datetime.year().map_or(Value::None, |y| Value::Int(y.into())) + } + "month" => { + datetime.month().map_or(Value::None, |m| Value::Int(m.into())) + } + "weekday" => { + datetime.weekday().map_or(Value::None, |w| Value::Int(w.into())) + } + "day" => datetime.day().map_or(Value::None, |d| Value::Int(d.into())), + "hour" => { + datetime.hour().map_or(Value::None, |h| Value::Int(h.into())) + } + "minute" => { + datetime.minute().map_or(Value::None, |m| Value::Int(m.into())) + } + "second" => { + datetime.second().map_or(Value::None, |s| Value::Int(s.into())) + } + _ => return missing(), + } } else { return (vm.items.library_method)(vm, &dynamic, method, args, span); } -- cgit v1.2.3