summaryrefslogtreecommitdiff
path: root/src/eval/methods.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval/methods.rs')
-rw-r--r--src/eval/methods.rs25
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);
}