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:
@@ -2,6 +2,7 @@ import { Controller, useFieldArray } from 'react-hook-form';
|
||||
import type { Control, UseFormRegister } from 'react-hook-form';
|
||||
import type { BlogFormData } from '../lib/blogForm';
|
||||
import PersianDatePicker from './ui/PersianDatePicker';
|
||||
import { toGregorianDate, toTehranClockTime, tehranWallClockToUnix } from '../lib/utils';
|
||||
|
||||
interface Props {
|
||||
control: Control<BlogFormData>;
|
||||
@@ -90,16 +91,16 @@ export default function BlogSeoFields({ control, register }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Gregorian date + time → unix seconds, and back. */
|
||||
/** Gregorian date + time → unix seconds, and back — همیشه به وقت ایران. */
|
||||
function ScheduleField({ value, onChange }: { value: number | null; onChange: (v: number | null) => void }) {
|
||||
const d = value ? new Date(value * 1000) : null;
|
||||
const dateStr = d ? d.toISOString().slice(0, 10) : '';
|
||||
const timeStr = d ? d.toTimeString().slice(0, 5) : '00:00';
|
||||
const dateStr = d ? toGregorianDate(d) : '';
|
||||
const timeStr = d ? toTehranClockTime(d) : '00:00';
|
||||
|
||||
const emit = (nextDate: string, nextTime: string) => {
|
||||
if (!nextDate) return onChange(null);
|
||||
const ms = Date.parse(`${nextDate}T${nextTime || '00:00'}:00`);
|
||||
onChange(Number.isNaN(ms) ? null : Math.floor(ms / 1000));
|
||||
const ts = tehranWallClockToUnix(nextDate, nextTime || '00:00');
|
||||
onChange(Number.isNaN(ts) ? null : ts);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user