refactor: normalize date handling to Tehran timezone
- Updated date handling in BlogSeoFields and ScheduleSection to use Tehran timezone utilities for consistency. - Introduced `toTehranClockTime`, `tehranWallClockToUnix`, and `todayIso` functions for accurate date representation. - Modified various components to utilize these new utilities, ensuring that date strings are correctly formatted and timestamps are accurately converted. - Enhanced API documentation to clarify the handling of date fields, emphasizing the importance of server-local midnight. - Added tests to verify that date overrides and holidays maintain the correct day without shifting due to timezone discrepancies.
This commit is contained in:
@@ -87,6 +87,14 @@ export function toGregorianDate(d: Date): string {
|
||||
}).format(d);
|
||||
}
|
||||
|
||||
// ساعت دیواریِ ایران به صورت «HH:MM» با رقم لاتین — برای مقداردهی <input type="time">
|
||||
// (بر خلاف formatTime که رقم فارسی میدهد و در input معتبر نیست).
|
||||
export function toTehranClockTime(d: Date): string {
|
||||
return new Intl.DateTimeFormat('en-GB', {
|
||||
timeZone: APP_TZ, hour12: false, hour: '2-digit', minute: '2-digit',
|
||||
}).format(d);
|
||||
}
|
||||
|
||||
// API stores contract dates as Unix seconds; the date input speaks Y-m-d strings.
|
||||
export function isoToUnix(iso: string): number | null {
|
||||
const d = toDate(iso);
|
||||
@@ -98,6 +106,12 @@ export function unixToIso(ts: number | null | undefined): string {
|
||||
return toGregorianDate(new Date(ts * 1000));
|
||||
}
|
||||
|
||||
// «امروز» به وقت ایران. هرگز از `new Date().toISOString().slice(0,10)` استفاده نکن؛
|
||||
// آن تاریخِ UTC است و بعد از ۲۰:۳۰ بهوقت تهران یک روز جلو میافتد.
|
||||
export function todayIso(): string {
|
||||
return toGregorianDate(new Date());
|
||||
}
|
||||
|
||||
// عنوان «دکتر» فقط در نمایش افزوده میشود و هرگز در فیلد name دیتابیس ذخیره نمیشود
|
||||
// (backend با stripDoctorTitle حذف میکند). این helper تنها نقطهٔ افزودن عنوان است تا
|
||||
// در کل پنل یکسان باشد و از «دکتر دکتر …» یا نمایش بدون عنوان جلوگیری شود.
|
||||
|
||||
Reference in New Issue
Block a user