MCPcopy
hub / github.com/node-cron/node-cron / getTimezoneGMT

Function getTimezoneGMT

src/time/localized-time.ts:196–218  ·  view source on GitHub ↗
(date: Date, timezone?: string)

Source from the content-addressed store, hash-verified

194}
195
196function getTimezoneGMT(date: Date, timezone?: string) {
197 const fmt = getOffsetFormatter(timezone);
198 const parts = fmt.formatToParts(date);
199 const tzPart = parts.find(p => p.type === 'timeZoneName');
200 if (!tzPart) return 'Z';
201
202 const tzValue = tzPart.value; // e.g. "GMT-5", "GMT+5:30", "GMT"
203 if (tzValue === 'GMT') return 'Z';
204
205 // Parse the offset from the Intl-provided string
206 const match = tzValue.match(/^GMT([+-])(\d{1,2})(?::(\d{2}))?$/);
207 if (!match) return 'Z';
208
209 const sign = match[1];
210 const hoursNum = parseInt(match[2]);
211 const minutesNum = parseInt(match[3] || '0');
212 if (hoursNum === 0 && minutesNum === 0) return 'Z';
213
214 const hours = match[2].padStart(2, '0');
215 const minutes = (match[3] || '00').padStart(2, '0');
216
217 return `GMT${sign}${hours}:${minutes}`;
218}

Callers 2

getOffsetMinutesFunction · 0.85
getFunction · 0.85

Calls 2

getOffsetFormatterFunction · 0.85
matchMethod · 0.65

Tested by

no test coverage detected