Skip to content

Commit

Permalink
Fixes #3674
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Mar 4, 2025
1 parent fa30c8a commit 6957ff4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ class Template extends TemplateContent {

if (dateValue) {
debug("getMappedDate: using a date in the data for %o of %o", this.inputPath, data.date);
if (dateValue instanceof DateTime) {
if (dateValue?.constructor?.name === "DateTime") {
// YAML does its own date parsing
debug("getMappedDate: found DateTime instance: %o", dateValue);
return dateValue.toJSDate();
Expand Down
24 changes: 24 additions & 0 deletions test/EleventyTest-CustomDateParsing.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { createRequire } from "node:module";
import test from "ava";
import { DateTime } from "luxon";
import Eleventy from "../src/Eleventy.js";

const require = createRequire(import.meta.url);

test("Custom date parsing callback (return string), Issue #867", async (t) => {
t.plan(3);

Expand Down Expand Up @@ -169,3 +172,24 @@ test("Custom date parsing callbacks (two, last wins, return string), Issue #867"
let [result] = await elev.toJSON();
t.deepEqual(result.data.page.date, new Date(Date.UTC(2001,0,1,12)));
});

// https://github.com/11ty/eleventy/issues/3674
test("instanceof DateTime issue, Issue #3674", async (t) => {
const { DateTime } = require("luxon");

// this test *requires* a non-virtual template to repro
let elev = new Eleventy("./test/stubs/index.html", undefined, {
config: eleventyConfig => {
eleventyConfig.addTemplate("test.html", `# Markdown`);
eleventyConfig.dataFilterSelectors.add("page.date");

eleventyConfig.addDateParsing(function (dateValue) {
return DateTime.fromISO("2001-01-01T12:00:00Z");
});
}
});
elev.disableLogger();

let [result] = await elev.toJSON();
t.deepEqual(result.data.page.date, new Date(Date.UTC(2001,0,1,12)));
});

0 comments on commit 6957ff4

Please sign in to comment.