summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--library/src/compute/data.rs21
-rw-r--r--src/eval/datetime.rs4
-rw-r--r--tests/typ/compute/data.typ9
3 files changed, 29 insertions, 5 deletions
diff --git a/library/src/compute/data.rs b/library/src/compute/data.rs
index b236536d..1238c3c3 100644
--- a/library/src/compute/data.rs
+++ b/library/src/compute/data.rs
@@ -1,4 +1,5 @@
use typst::diag::{format_xml_like_error, FileError};
+use typst::eval::Datetime;
use crate::prelude::*;
@@ -268,8 +269,24 @@ fn convert_toml(value: toml::Value) -> Value {
.map(|(key, value)| (key.into(), convert_toml(value)))
.collect::<Dict>()
.into_value(),
- // TODO: Make it use native date/time object(s) once it is implemented.
- toml::Value::Datetime(v) => v.to_string().into_value(),
+ toml::Value::Datetime(v) => match (v.date, v.time) {
+ (None, None) => Value::None,
+ (Some(date), None) => {
+ Datetime::from_ymd(date.year as i32, date.month, date.day).into_value()
+ }
+ (None, Some(time)) => {
+ Datetime::from_hms(time.hour, time.minute, time.second).into_value()
+ }
+ (Some(date), Some(time)) => Datetime::from_ymd_hms(
+ date.year as i32,
+ date.month,
+ date.day,
+ time.hour,
+ time.minute,
+ time.second,
+ )
+ .into_value(),
+ },
}
}
diff --git a/src/eval/datetime.rs b/src/eval/datetime.rs
index 57d0683d..f3c4a5a1 100644
--- a/src/eval/datetime.rs
+++ b/src/eval/datetime.rs
@@ -16,9 +16,9 @@ pub enum Datetime {
/// Representation as a date.
Date(time::Date),
/// Representation as a time.
- Datetime(time::PrimitiveDateTime),
- /// Representation as a combination of date and time.
Time(time::Time),
+ /// Representation as a combination of date and time.
+ Datetime(time::PrimitiveDateTime),
}
impl Datetime {
diff --git a/tests/typ/compute/data.typ b/tests/typ/compute/data.typ
index 96b655c0..d67b7aef 100644
--- a/tests/typ/compute/data.typ
+++ b/tests/typ/compute/data.typ
@@ -48,11 +48,18 @@
#test(data.integer, 42)
#test(data.float, 3.14)
#test(data.boolean, true)
-#test(data.date_time, "2023-02-01T15:38:57Z")
#test(data.array, (1, "string", 3.0, false))
#test(data.inline_table, ("first": "amazing", "second": "greater") )
#test(data.table.element, 5)
#test(data.table.others, (false, "indeed", 7))
+#test(data.date_time, datetime(
+ year: 2023,
+ month: 2,
+ day: 1,
+ hour: 15,
+ minute: 38,
+ second: 57,
+))
---
// Error: 7-18 failed to parse toml file: expected `.`, `=`, index 15-15