Files
RSSHub/lib/utils/parse-date-in-timezone.ts
Tony a794017637 fix(route/smzdm): drop cookie hard requirement (#23490)
* fix(route/smzdm): drop cookie hard requirement

* fix(parse-date-in-timezone): correct import path for utc plugin
2026-10-06 10:04:27 +08:00

17 lines
691 B
TypeScript

import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';
dayjs.extend(utc);
const isWallClockCandidate = (date: string | number | Date): date is string => typeof date === 'string';
// Interpret a source's wall clock without using the host's timezone. Dates,
// timestamps and ISO strings with an explicit offset already identify an instant.
export const parseDateInTimezone = (date: string | number | Date, offset: number): Date => {
const parsed = dayjs.utc(date);
if (!isWallClockCandidate(date) || /(?:Z|[+-]\d{2}:?\d{2}|(?:GMT|UTC)(?:[+-]\d{1,4})?)$/i.test(date.trim())) {
return parsed.toDate();
}
return parsed.subtract(offset, 'hour').toDate();
};