31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
/**
|
|
* ponytail: assert Tehran display formatting (fixed +03:30).
|
|
* Run: node scripts/check-format-display-datetime.js
|
|
*
|
|
* Standalone copy of offset math — CRA ESM can't require() the helper.
|
|
* Keep in sync with src/core/helper/formatDisplayDateTime.js
|
|
*/
|
|
const assert = require("assert");
|
|
|
|
const TEHRAN_UTC_OFFSET_MINUTES = 210;
|
|
|
|
function formatTehranFromUnixSec(unixSec, pattern) {
|
|
// 2024-01-15T12:00:00Z → Tehran 15:30
|
|
const ms = unixSec * 1000 + TEHRAN_UTC_OFFSET_MINUTES * 60 * 1000;
|
|
const d = new Date(ms);
|
|
const hh = String(d.getUTCHours()).padStart(2, "0");
|
|
const mm = String(d.getUTCMinutes()).padStart(2, "0");
|
|
const ss = String(d.getUTCSeconds()).padStart(2, "0");
|
|
if (pattern === "time") return `${Number(hh)}:${mm}:${ss}`.replace(/^0/, "") || `${hh}:${mm}:${ss}`;
|
|
// Just assert hour/minute components for smoke
|
|
return { hour: d.getUTCHours(), minute: d.getUTCMinutes() };
|
|
}
|
|
|
|
// 1705320000 = 2024-01-15T12:00:00.000Z → Tehran 15:30
|
|
const parts = formatTehranFromUnixSec(1705320000, "full");
|
|
assert.strictEqual(parts.hour, 15, "Tehran hour for 12:00Z");
|
|
assert.strictEqual(parts.minute, 30, "Tehran minute for 12:00Z");
|
|
assert.strictEqual(TEHRAN_UTC_OFFSET_MINUTES, 210);
|
|
|
|
console.log("check-format-display-datetime: ok");
|