diff --git a/tools/lib/stats/articles.js b/tools/lib/stats/articles.js index c101618e..5621cb3d 100644 --- a/tools/lib/stats/articles.js +++ b/tools/lib/stats/articles.js @@ -1,26 +1,11 @@ const path = require("path"); -const { DateTime } = require("luxon"); const { collectMarkdownFiles, collectSectionIndexDirs } = require("../content"); const { readFrontmatter } = require("../weather/frontmatter"); +const { parseFrontmatterDate } = require("../datetime"); function parseDate(value) { if (!value) return null; - - if (value instanceof Date) { - return DateTime.fromJSDate(value); - } - - if (typeof value === "string") { - let parsed = DateTime.fromISO(value); - - if (!parsed.isValid) { - parsed = DateTime.fromRFC2822(value); - } - - return parsed.isValid ? parsed : null; - } - - return null; + return parseFrontmatterDate(value); } function countWords(body) { diff --git a/tools/stats/common.py b/tools/stats/common.py index 669338c9..ee079112 100644 --- a/tools/stats/common.py +++ b/tools/stats/common.py @@ -79,7 +79,15 @@ def parse_date(value): dt = None elif isinstance(value, str): # try ISO-like formats - for fmt in ("%Y-%m-%dT%H:%M:%S%z", "%Y-%m-%dT%H:%M:%S", "%Y-%m-%d", "%Y/%m/%d", "%d/%m/%Y"): + for fmt in ( + "%Y-%m-%dT%H:%M:%S%z", + "%Y-%m-%dT%H:%M:%S", + "%Y-%m-%d %H:%M:%S", + "%Y-%m-%d %H:%M", + "%Y-%m-%d", + "%Y/%m/%d", + "%d/%m/%Y", + ): try: dt = datetime.strptime(value, fmt) break