Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

fix(ingest): preserve Excel calendar dateTime values

Rudy Celeklid3b7f7344b14
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3d864085..3c6c73f0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,6 +46,11 @@ All notable changes to Open Ontologies are documented here.
### Fixed
+- Render XLSX numeric calendar cells as ISO dateTime values instead of Excel
+ serial numbers, respecting the workbook's 1900 or 1904 calendar. Duration
+ cells retain their existing representation; calendar cells do not distinguish
+ date-only values from midnight dateTimes.
+
- **The embedding model is loaded once per process rather than once per HTTP
session** (#262). The HTTP arm hands the same server constructor to
`StreamableHttpService::new` as a per-session factory, so everything that
diff --git a/Cargo.lock b/Cargo.lock
index fd9337b2..cd3b1069 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -795,6 +795,7 @@ checksum = "b1a9acfeb1555aa8def91fe8ff208aadaea850c109968ec35ac965edbe7d210b"
dependencies = [
"atoi_simd",
"byteorder",
+ "chrono",
"codepage",
"encoding_rs",
"fast-float2",
diff --git a/Cargo.toml b/Cargo.toml
index e01e1afe..6d49e5d3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -56,7 +56,7 @@ rayon = "1.10"
csv = "1"
quick-xml = { version = "0.37", features = ["serialize"] }
serde_yaml = "0.9"
-calamine = "0.30"
+calamine = { version = "0.30", features = ["dates"] }
arrow = { version = "54", default-features = false, features = ["csv", "json"] }
parquet = { version = "54", default-features = false, features = ["arrow"] }
sqlx = { version = "0.8", default-features = false, features = ["runtime-tokio", "postgres"], optional = true }
diff --git a/src/ingest.rs b/src/ingest.rs
index 2f6ed7ad..7143dbe1 100644
--- a/src/ingest.rs
+++ b/src/ingest.rs
@@ -256,6 +256,10 @@ impl DataIngester {
calamine::Data::Float(f) => f.to_string(),
calamine::Data::String(s) => s.clone(),
calamine::Data::Bool(b) => b.to_string(),
+ calamine::Data::DateTime(dt) if dt.is_datetime() => dt
+ .as_datetime()
+ .map(|value| value.format("%Y-%m-%dT%H:%M:%S%.f").to_string())
+ .unwrap_or_else(|| dt.to_string()),
calamine::Data::DateTime(dt) => dt.to_string(),
calamine::Data::DateTimeIso(s) => s.clone(),
calamine::Data::DurationIso(s) => s.clone(),
diff --git a/tests/fixtures/ingest/excel-calendar-1900.xlsx b/tests/fixtures/ingest/excel-calendar-1900.xlsx
new file mode 100644
index 00000000..34c432fa
Binary files /dev/null and b/tests/fixtures/ingest/excel-calendar-1900.xlsx differ
diff --git a/tests/fixtures/ingest/excel-calendar-1904.xlsx b/tests/fixtures/ingest/excel-calendar-1904.xlsx
new file mode 100644
index 00000000..8b8777e0
Binary files /dev/null and b/tests/fixtures/ingest/excel-calendar-1904.xlsx differ
diff --git a/tests/fixtures/ingest/excel-calendar-iso.xlsx b/tests/fixtures/ingest/excel-calendar-iso.xlsx
new file mode 100644
index 00000000..db1f7499
Binary files /dev/null and b/tests/fixtures/ingest/excel-calendar-iso.xlsx differ
diff --git a/tests/ingest_excel_calendar_test.rs b/tests/ingest_excel_calendar_test.rs
new file mode 100644
index 00000000..501b9c60
--- /dev/null
+++ b/tests/ingest_excel_calendar_test.rs
@@ -0,0 +1,80 @@
+use open_ontologies::graph::GraphStore;
+use open_ontologies::induce::{Dt, induce};
+use open_ontologies::ingest::DataIngester;
+use open_ontologies::mapping::{FieldMapping, MappingConfig};
+
+fn fixture(name: &str) -> String {
+ std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("tests/fixtures/ingest")
+ .join(name)
+ .to_str()
+ .unwrap()
+ .to_owned()
+}
+
+#[test]
+fn both_excel_calendars_preserve_datetimes_and_other_cell_types() {
+ for name in ["excel-calendar-1900.xlsx", "excel-calendar-1904.xlsx"] {
+ let rows = DataIngester::parse_xlsx_file(&fixture(name)).unwrap();
+ assert_eq!(rows.len(), 1);
+ assert_eq!(rows[0]["midnight"], "2026-10-06T00:00:00");
+ assert_eq!(rows[0]["datetime"], "2026-10-06T13:14:15.123");
+ assert_eq!(
+ rows[0]["duration"], "1.5",
+ "elapsed time is not a calendar date"
+ );
+ assert_eq!(
+ rows[0]["number"], "46301",
+ "unformatted numbers remain numbers"
+ );
+ assert_eq!(rows[0]["boolean"], "true");
+ assert_eq!(rows[0]["empty"], "");
+ assert_eq!(rows[0]["error"], "Div0");
+ let headers = DataIngester::extract_headers(&rows);
+ let inferred = induce(&rows, &headers, "Rows", "https://example.org/rows/");
+ for field in ["midnight", "datetime"] {
+ assert_eq!(
+ inferred
+ .columns
+ .iter()
+ .find(|column| column.property == field)
+ .unwrap()
+ .datatype,
+ Dt::DateTime
+ );
+ }
+ }
+}
+
+#[test]
+fn serial_and_iso_cells_match_csv_and_keep_an_explicit_datetime_mapping() {
+ let csv = DataIngester::parse_csv("id,datetime\nrow-1,2026-10-06T13:14:15.123\n").unwrap();
+ let iso = DataIngester::parse_xlsx_file(&fixture("excel-calendar-iso.xlsx")).unwrap();
+ let mapping = MappingConfig {
+ base_iri: "https://example.org/rows/".into(),
+ id_field: "id".into(),
+ class: "https://example.org/Row".into(),
+ mappings: vec![FieldMapping {
+ field: "datetime".into(),
+ predicate: "https://example.org/when".into(),
+ datatype: Some("http://www.w3.org/2001/XMLSchema#dateTime".into()),
+ class: None,
+ lookup: false,
+ }],
+ };
+ for name in ["excel-calendar-1900.xlsx", "excel-calendar-1904.xlsx"] {
+ let rows = DataIngester::parse_xlsx_file(&fixture(name)).unwrap();
+ assert_eq!(rows[0]["datetime"], csv[0]["datetime"]);
+ assert_eq!(rows[0]["datetime"], iso[0]["datetime"]);
+ let triples = mapping.rows_to_ntriples(&rows);
+ let store = GraphStore::new();
+ store.load_ntriples(&triples).unwrap();
+ let query = store.sparql_select(
+ "SELECT (DATATYPE(?value) AS ?datatype) WHERE { ?s <https://example.org/when> ?value }",
+ ).unwrap();
+ assert!(
+ query.contains("http://www.w3.org/2001/XMLSchema#dateTime"),
+ "{query}"
+ );
+ }
+}