From bbf2b885d729e72f528d4719506f1c9d6c8ca3c1 Mon Sep 17 00:00:00 2001 From: bangonicdd <157843588+bangonicdd2@users.noreply.github.com> Date: Fri, 12 Jul 2024 01:09:26 +0900 Subject: [PATCH 1/2] Refactor dateTimeFormat --- src/ts/parser.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 312322c5..88658a19 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -1496,17 +1496,19 @@ const dateTimeFormat = (main:string, time = 0) => { return main .replace(/YYYY/g, date.getFullYear().toString()) .replace(/YY/g, date.getFullYear().toString().substring(2)) - .replace(/MM?/g, (date.getMonth() + 1).toString().padStart(2, '0')) - .replace(/DD?/g, date.getDate().toString().padStart(2, '0')) - .replace(/DDDD?/g, (date.getDay() + (date.getMonth() * 30)).toString()) - .replace(/HH?/g, date.getHours().toString().padStart(2, '0')) - .replace(/hh?/g, (date.getHours() % 12).toString().padStart(2, '0')) - .replace(/mm?/g, date.getMinutes().toString().padStart(2, '0')) - .replace(/ss?/g, date.getSeconds().toString().padStart(2, '0')) - .replace(/X?/g, (Date.now() / 1000).toFixed(2)) - .replace(/x?/g, Date.now().toFixed()) + .replace(/MMMM/g, Intl.DateTimeFormat('en', { month: 'long' }).format(date)) + .replace(/MM/g, (date.getMonth() + 1).toString().padStart(2, '0')) + .replace(/DDDD/g, Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / (1000 * 60 * 60 * 24)).toString()) + .replace(/DD/g, date.getDate().toString().padStart(2, '0')) + .replace(/dddd/g, Intl.DateTimeFormat('en', { weekday: 'long' }).format(date)) + .replace(/ddd/g, Intl.DateTimeFormat('en', { weekday: 'short' }).format(date)) + .replace(/HH/g, date.getHours().toString().padStart(2, '0')) + .replace(/hh/g, (date.getHours() % 12 || 12).toString().padStart(2, '0')) + .replace(/mm/g, date.getMinutes().toString().padStart(2, '0')) + .replace(/ss/g, date.getSeconds().toString().padStart(2, '0')) + .replace(/X/g, Math.floor(date.getTime() / 1000).toString()) + .replace(/x/g, date.getTime().toString()) .replace(/A/g, date.getHours() >= 12 ? 'PM' : 'AM') - .replace(/MMMM?/g, Intl.DateTimeFormat('en', { month: 'long' }).format(date)) } From 5d5a01b0cb4cde26110251368ec1b07aa1dda0ac Mon Sep 17 00:00:00 2001 From: bangonicdd <157843588+bangonicdd2@users.noreply.github.com> Date: Fri, 12 Jul 2024 19:38:24 +0900 Subject: [PATCH 2/2] add date format for short month --- src/ts/parser.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 88658a19..94acbda3 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -1497,6 +1497,7 @@ const dateTimeFormat = (main:string, time = 0) => { .replace(/YYYY/g, date.getFullYear().toString()) .replace(/YY/g, date.getFullYear().toString().substring(2)) .replace(/MMMM/g, Intl.DateTimeFormat('en', { month: 'long' }).format(date)) + .replace(/MMM/g, Intl.DateTimeFormat('en', { month: 'short' }).format(date)) .replace(/MM/g, (date.getMonth() + 1).toString().padStart(2, '0')) .replace(/DDDD/g, Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / (1000 * 60 * 60 * 24)).toString()) .replace(/DD/g, date.getDate().toString().padStart(2, '0'))