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 path = require("path");
|
||||||
const { DateTime } = require("luxon");
|
|
||||||
const { collectMarkdownFiles, collectSectionIndexDirs } = require("../content");
|
const { collectMarkdownFiles, collectSectionIndexDirs } = require("../content");
|
||||||
const { readFrontmatter } = require("../weather/frontmatter");
|
const { readFrontmatter } = require("../weather/frontmatter");
|
||||||
|
const { parseFrontmatterDate } = require("../datetime");
|
||||||
|
|
||||||
function parseDate(value) {
|
function parseDate(value) {
|
||||||
if (!value) return null;
|
if (!value) return null;
|
||||||
|
return parseFrontmatterDate(value);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function countWords(body) {
|
function countWords(body) {
|
||||||
|
|||||||
@@ -79,7 +79,15 @@ def parse_date(value):
|
|||||||
dt = None
|
dt = None
|
||||||
elif isinstance(value, str):
|
elif isinstance(value, str):
|
||||||
# try ISO-like formats
|
# 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:
|
try:
|
||||||
dt = datetime.strptime(value, fmt)
|
dt = datetime.strptime(value, fmt)
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user