mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-27 21:36:05 +08:00
* fix(route/smzdm): drop cookie hard requirement * fix(parse-date-in-timezone): correct import path for utc plugin
17 lines
691 B
TypeScript
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();
|
|
};
|