Skip to content

Commit c35afff

Browse files
authored
Fix timezone handling in rfc822_datetime function
1 parent f57dc15 commit c35afff

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

libreblog/libreblog.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,20 +1443,20 @@ const configTwig = function() {
14431443
});
14441444

14451445
globalThis.Twig.extendFunction('rfc822_datetime', (dt, tz) => {
1446-
const dateString = dt.replace(" ", "T") + (tz ? tz : "");
1446+
const dateString = dt.replace(" ", "T") + (tz ? tz : "Z");
14471447

14481448
const dayStrings = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
14491449
const monthStrings = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
14501450

14511451
const timeStamp = Date.parse(dateString);
14521452
const date = new Date(timeStamp);
14531453

1454-
const day = dayStrings[date.getDay()];
1455-
const dayNumber = addLeadingZero(date.getDate());
1456-
const month = monthStrings[date.getMonth()];
1457-
const year = date.getFullYear();
1458-
const time = `${addLeadingZero(date.getHours())}:${addLeadingZero(date.getMinutes())}:00`;
1459-
const timezone = date.getTimezoneOffset() === 0 ? "GMT" : "BST";
1454+
const day = dayStrings[date.getUTCDay()];
1455+
const dayNumber = addLeadingZero(date.getUTCDate());
1456+
const month = monthStrings[date.getUTCMonth()];
1457+
const year = date.getUTCFullYear();
1458+
const time = `${addLeadingZero(date.getUTCHours())}:${addLeadingZero(date.getUTCMinutes())}:00`;
1459+
const timezone = "GMT";
14601460

14611461
return `${day}, ${dayNumber} ${month} ${year} ${time} ${timezone}`;
14621462
});

0 commit comments

Comments
 (0)