Changeset a7bcf66 in Klonkt for src/middleware/render.js
- Timestamp:
- 07/28/2026 06:30:43 PM (6 weeks ago)
- Branches:
- main
- Children:
- 70677e96
- Parents:
- d9ad6c5
- File:
-
- 1 edited
-
src/middleware/render.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/middleware/render.js
rd9ad6c5 ra7bcf66 85 85 const siteTimezone = () => getSetting('timezone') || undefined; 86 86 87 /** 88 * Read a stored timestamp as the moment it actually is. 89 * 90 * SQLite's CURRENT_TIMESTAMP writes UTC without saying so ("2026-07-28 91 * 18:20:33"), and new Date() reads a string in that shape as LOCAL time. That 92 * is right only as long as the server runs on UTC; set the machine to 93 * Europe/Amsterdam and every stored date silently shifts two hours. So say UTC 94 * out loud. Anything already carrying a zone (AP `published` ends in Z) is left 95 * to the normal parser. 96 */ 97 const parseStamp = (v) => { 98 if (!v) return null; 99 const s = String(v); 100 const d = /^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}(:\d{2})?$/.test(s) 101 ? new Date(`${s.replace(' ', 'T')}Z`) 102 : new Date(s); 103 return Number.isNaN(d.getTime()) ? null : d; 104 }; 105 87 106 const formatDate = (iso) => { 88 if (!iso) return '';89 return new Date(iso).toLocaleDateString('nl-NL', { timeZone: siteTimezone(), day: 'numeric', month: 'long', year: 'numeric' });107 const d = parseStamp(iso); 108 return d ? d.toLocaleDateString('nl-NL', { timeZone: siteTimezone(), day: 'numeric', month: 'long', year: 'numeric' }) : ''; 90 109 }; 91 110 92 const formatDateTime = (iso) => { 93 if (!iso) return ''; 94 return new Date(iso).toLocaleString('nl-NL', { timeZone: siteTimezone(), dateStyle: 'medium', timeStyle: 'short' }); 111 /** A timestamp in the site's own timezone (Beheer → Instellingen). Exported so 112 * surfaces outside the EJS pages (the Guardian PWA) read the same clock. */ 113 export const formatDateTime = (iso) => { 114 const d = parseStamp(iso); 115 return d ? d.toLocaleString('nl-NL', { timeZone: siteTimezone(), dateStyle: 'medium', timeStyle: 'short' }) : ''; 95 116 }; 96 117
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)