-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration Hook/callback for custom date
parsing
#867
Comments
I second this. Other quick fixes seem like hacks. |
Hmm, after seeing some pain in #822 too it does seem good to at least provide a configuration hook to add additional userland date parsing options. |
date
parsing
|
Cross linking to #879 (linting data) |
I'd love to see this change! For some time I've thought about removing the custom |
Related #3315 |
… return will fallback to the previous behavior. #867
v3.0.0-alpha.15 will include an You can return:
Here’s an example using IANA time zone codes from the Eleventy test suite. ---
date: 2019-08-31 23:59:56 America/New_York
---
# Markdown import { DateTime } from "luxon";
export default function(eleventyConfig) {
eleventyConfig.addDateParsing(function(dateValue) {
return DateTime.fromFormat(dateValue, "yyyy-MM-dd hh:mm:ss z");
});
}; You can add multiple callbacks and chain them together and they’ll all run before the fallback logic takes hold of the new value: eleventyConfig.addDateParsing((rawDateValueFromTemplate) => rawDateValueFromTemplate);
eleventyConfig.addDateParsing((rawDateValueFromFirstCallback) => rawDateValueFromFirstCallback); |
Wow that's amazing, thanks Zach! Exactly what I was looking for. |
Preview docs deploying here: https://11ty-website-git-v3-11ty.vercel.app/docs/dates/#configuration-api-for-custom-date-parsing |
I'd like to use IANA time zone codes for specifying localized time in post dates, like so:
In my humble opinion this would be the best way to avoid the dates off by one day pitfall.
Unlike UTC-based time offsets (e.g.
+01:00
), IANA codes abstract away offset differences from Daylight Saving Time, so a single value magically works all year round. They're also easier to understand, and provide a bit more geographical context, which is a nice bonus.IANA codes are supported in Luxon, represented by the
z
token.Eleventy currently rejects this date format as invalid, but it works in Jekyll. I'm porting over my Jekyll blog, and with over 800 posts all using this date format, um, help
The text was updated successfully, but these errors were encountered: