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:
hamed
2026-07-27 19:37:44 +03:30
parent 2963e2ac74
commit b423a0ae4d
21 changed files with 267 additions and 57 deletions
+7 -2
View File
@@ -9,11 +9,16 @@ import type { PatientProfile } from '@/types';
import type { PatientFormValues } from '@/components/PatientRecordInfoForm';
describe('date helpers', () => {
it('timestamp ↔ YYYY-MM-DD رفت‌وبرگشت', () => {
// مبنا نیمه‌شبِ تهران است (نه UTC)، چون بک‌اند هم تاریخ‌های روزمحور را با
// strtotime در تایم‌زون سرور (Asia/Tehran) ذخیره می‌کند.
it('timestamp ↔ YYYY-MM-DD رفت‌وبرگشت روی نیمه‌شبِ تهران', () => {
const ts = dateStrToTs('2025-01-07');
expect(ts).toBe(Math.floor(Date.parse('2025-01-07T00:00:00Z') / 1000));
expect(ts).toBe(Math.floor(Date.UTC(2025, 0, 6, 20, 30, 0) / 1000));
expect(tsToDateStr(ts)).toBe('2025-01-07');
});
it('timestampهای ساخته‌شده توسط سرور یک روز عقب نمی‌روند', () => {
expect(tsToDateStr(Math.floor(Date.UTC(2026, 6, 28, 20, 30, 0) / 1000))).toBe('2026-07-29');
});
it('خالی/نامعتبر → مقدار تهی', () => {
expect(tsToDateStr(null)).toBe('');
expect(tsToDateStr(0)).toBe('');