Website : rimsha.abasa.com
backdoor
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
mudeerapi.abasa.com
/
nodetest
/
src
/
utils
/
Filename :
timezone.js
back
Copy
const MAKKAH_UTC_OFFSET_MINUTES = 3 * 60; // UTC+3 without DST /** * Converts a 12-hour clock string stored in Makkah local time * (e.g. "08:30 AM") into a Date object aligned to the provided * reference date in UTC. * * The stored value remains untouched; use this helper wherever * UTC-aware comparisons are required. * * @param {string} timeString - 12-hour formatted time (HH:MM AM/PM) * @param {Date} referenceDate - Date whose UTC day is used (defaults to now) * @returns {Date} UTC Date representing the same instant */ export const convertMakkahTimeStringToUTC = (timeString, referenceDate = new Date()) => { if (!timeString || typeof timeString !== 'string') { throw new Error('Invalid time string provided for conversion'); } const [timePart, modifier = 'AM'] = timeString.trim().split(' '); let [hours, minutes] = timePart.split(':').map((value) => parseInt(value, 10)); if (isNaN(hours) || isNaN(minutes)) { throw new Error(`Unable to parse time string "${timeString}"`); } const normalizedModifier = modifier.toUpperCase(); if (normalizedModifier === 'PM' && hours !== 12) { hours += 12; } else if (normalizedModifier === 'AM' && hours === 12) { hours = 0; } const makkahMinutes = hours * 60 + minutes; const utcMinutes = makkahMinutes - MAKKAH_UTC_OFFSET_MINUTES; const utcDate = new Date(Date.UTC( referenceDate.getUTCFullYear(), referenceDate.getUTCMonth(), referenceDate.getUTCDate(), 0, 0, 0, 0 )); // Date takes care of day rollover when minutes are <0 or >1440 utcDate.setUTCMinutes(utcMinutes); return utcDate; };