1
0
forked from Yara724/api

Fixed timing issue with UTC

This commit is contained in:
SepehrYahyaee
2026-05-16 10:28:32 +03:30
parent e4d6246103
commit 2c851725a5
3 changed files with 114 additions and 21 deletions

View File

@@ -41,6 +41,7 @@ import { ReqBlameStatus } from "src/Types&Enums/blame-request-management/status.
import { StepsEnum } from "src/Types&Enums/blame-request-management/steps.enum";
import { ExpertDbService } from "src/users/entities/db-service/expert.db.service";
import { UserDbService } from "src/users/entities/db-service/user.db.service";
import { parseIranLocalDateTime } from "src/helpers/iran-datetime";
import { AutoCloseRequestService } from "src/utils/cron/cron.service";
import { SmsOrchestrationService } from "src/sms-orchestration/sms-orchestration.service";
import {
@@ -395,32 +396,16 @@ export class RequestManagementService {
/**
* Best-effort parser that combines a date input with an optional `HH:MM`
* time. Accepts a `Date`, an ISO datetime string, or an ISO date-only
* string so DTO payloads (which currently send `"YYYY-MM-DD"` + `"HH:MM"`)
* can be passed through directly. Returns `null` when the result is not a
* finite instant.
* time in Iran (Asia/Tehran, UTC+3:30). Accepts a `Date`, an ISO datetime
* string, or an ISO date-only string so DTO payloads (which send
* `"YYYY-MM-DD"` + `"HH:MM"` in local Iran time) can be passed through
* directly. Returns `null` when the result is not a finite instant.
*/
private parseAccidentInstant(
date: Date | string,
time?: string,
): Date | null {
if (date instanceof Date) {
return Number.isNaN(date.getTime()) ? null : date;
}
const raw = String(date).trim();
if (!raw) return null;
// Already a full datetime — trust it and ignore the separate time field.
if (raw.includes("T") || /\s\d{1,2}:\d{2}/.test(raw)) {
const d = new Date(raw);
return Number.isNaN(d.getTime()) ? null : d;
}
const cleanTime = (time ?? "").trim();
const iso = cleanTime ? `${raw}T${cleanTime}` : raw;
const d = new Date(iso);
return Number.isNaN(d.getTime()) ? null : d;
return parseIranLocalDateTime(date, time);
}
/**