date comparisons (Intl API vs jalaali-js)

node v17.9.1
version: master
endpointsharetweet
const jalaali = require('jalaali-js') // this implementation is node.js's built-in API which is based on unicode-org/icu const intl = new Intl.DateTimeFormat("fa-IR", { numberingSystem: 'latn', year: 'numeric', month: '2-digit', day: '2-digit' }); const getIntlDate = (date) => intl.format(new Date(date)); // this implementation is based on jalaali-js const getJalaaliDate = (date) => { const zeroPad = (num) => num < 10 ? `0${num}` : num; const { jy, jm, jd } = jalaali.toJalaali(new Date(date)); return `${jy}/${zeroPad(jm)}/${zeroPad(jd)}`; } const compareIntlVsJalaali = (date) => ({ intlDate: getIntlDate(date), jalaaliDate: getJalaaliDate(date), }); const findContradictionInIntlVsJalaali = () => { const startingDate = new Date('1800-01-01'); const oneDay = 24 * 60 * 60 * 1000; let count = 0; while (true) { const date = new Date(count * oneDay + startingDate.getTime()) const { intlDate, jalaaliDate } = compareIntlVsJalaali(date); if (intlDate !== jalaaliDate) { return { intlDate, jalaaliDate }; } count++; } } console.log("first inconsistency in jalali leap years (intl vs jalaali):"); console.log(findContradictionInIntlVsJalaali());
Loading…

no comments

    sign in to comment