Correction de la gestion des dates dans les scripts de stats
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user