diff options
| author | Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> | 2023-05-23 10:41:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-23 10:41:20 +0200 |
| commit | 752817ae74607ca23ec0aad51824ddca66faa7a8 (patch) | |
| tree | d9f51f3d029c1ca8754be9ae9ccc9dc91ae6b000 /src/eval/methods.rs | |
| parent | f4fd6855e7fb833a2125d2e81aa3b9f548b18170 (diff) | |
Add support for date & time handling (#435)
Diffstat (limited to 'src/eval/methods.rs')
| -rw-r--r-- | src/eval/methods.rs | 25 |
1 files changed, 25 insertions, 0 deletions
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::<Datetime>() { + 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); } |
