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
+6 -4
View File
@@ -1,6 +1,7 @@
import type { SelectOption } from '../components/ui/SearchableSelect';
import type { PatientProfile, PatientProfileUpdate } from '../types';
import type { PatientFormValues } from '../components/PatientRecordInfoForm';
import { unixToIso, tehranWallClockToUnix } from './utils';
// ── enumهای ثابت فرم «اطلاعات پرونده» (بدون منبع API) ─────────────────────────
export const GENDER_OPTS: SelectOption[] = [
@@ -21,14 +22,15 @@ export const REFERRAL_OPTS: SelectOption[] = [
].map((v) => ({ value: v, label: v }));
// ── تبدیل تاریخ: timestamp ثانیه‌ای ↔ رشتهٔ میلادی YYYY-MM-DD ─────────────────
// هر دو سمت به وقت ایران‌اند تا با نیمه‌شبِ محلیِ ذخیره‌شده در بک‌اند هم‌راستا باشند؛
// تبدیل UTC روز را یک واحد جابه‌جا می‌کرد.
export function tsToDateStr(ts?: number | null): string {
if (!ts) return '';
return new Date(ts * 1000).toISOString().slice(0, 10);
return ts ? unixToIso(ts) : '';
}
export function dateStrToTs(s: string): number | null {
if (!s) return null;
const t = Date.parse(`${s}T00:00:00Z`);
return Number.isNaN(t) ? null : Math.floor(t / 1000);
const t = tehranWallClockToUnix(s, '00:00');
return Number.isNaN(t) ? null : t;
}
/** پروفایل API → مقادیر پیش‌فرض فرم. */