|
| 1 | +import dayjsOriginal, { ConfigType, Dayjs, OptionType } from "dayjs"; |
| 2 | +import customParseFormat from "dayjs/plugin/customParseFormat"; |
| 3 | +import dayOfYear from "dayjs/plugin/dayOfYear"; |
| 4 | +import isBetween from "dayjs/plugin/isBetween"; |
| 5 | +import isSameOrAfter from "dayjs/plugin/isSameOrAfter"; |
| 6 | +import isSameOrBefore from "dayjs/plugin/isSameOrBefore"; |
| 7 | +import timezone from "dayjs/plugin/timezone"; |
| 8 | +import utcPlugin from "dayjs/plugin/utc"; |
| 9 | +import weekOfYear from "dayjs/plugin/weekOfYear"; |
| 10 | +import weekday from "dayjs/plugin/weekday"; |
| 11 | + |
| 12 | +export type { |
| 13 | + ConfigType, |
| 14 | + ConfigTypeMap, |
| 15 | + Dayjs, |
| 16 | + DayjsTimezone, |
| 17 | + FormatObject, |
| 18 | + ManipulateType, |
| 19 | + OptionType, |
| 20 | + OpUnitType, |
| 21 | + PluginFunc, |
| 22 | + QUnitType, |
| 23 | + UnitType, |
| 24 | + UnitTypeLong, |
| 25 | + UnitTypeLongPlural, |
| 26 | + UnitTypeShort, |
| 27 | +} from "dayjs"; |
| 28 | + |
| 29 | +export { Ls } from "dayjs"; |
| 30 | + |
| 31 | +dayjsOriginal.extend(utcPlugin); |
| 32 | +dayjsOriginal.extend(timezone); |
| 33 | +dayjsOriginal.extend(weekday); |
| 34 | +dayjsOriginal.extend(dayOfYear); |
| 35 | +dayjsOriginal.extend(weekOfYear); |
| 36 | +dayjsOriginal.extend(isSameOrAfter); |
| 37 | +dayjsOriginal.extend(isSameOrBefore); |
| 38 | +dayjsOriginal.extend(isBetween); |
| 39 | +dayjsOriginal.extend(customParseFormat); // for RFC formatting |
| 40 | + |
| 41 | +export enum DateFormat { |
| 42 | + RFC5545 = "YYYYMMDD[T]HHmmss[Z]", |
| 43 | + RFC3339 = "YYYY-MM-DD[T]HH:mm:ss[Z]", |
| 44 | + RFC3339_OFFSET = "YYYY-MM-DDTHH:mm:ssZ", // can also be used as ISO8601 |
| 45 | +} |
| 46 | + |
| 47 | +const dayjs = function dayjs( |
| 48 | + date?: ConfigType, |
| 49 | + format?: OptionType, |
| 50 | + locale?: string, |
| 51 | + strict?: boolean, |
| 52 | +): Dayjs { |
| 53 | + return dayjsOriginal(date, format, locale, strict).tz(); |
| 54 | +} as unknown as typeof dayjsOriginal; |
| 55 | + |
| 56 | +dayjs.prototype = dayjsOriginal.prototype; |
| 57 | + |
| 58 | +Object.assign(dayjs, dayjsOriginal); |
| 59 | + |
| 60 | +export const extend = () => { |
| 61 | + throw new Error("dayjs extension is not supported."); |
| 62 | +}; |
| 63 | + |
| 64 | +export const isDayjs = dayjs.isDayjs.bind(dayjs); |
| 65 | +export const locale = dayjs.locale.bind(dayjs); |
| 66 | +export const tz = dayjs.tz.bind(dayjs); |
| 67 | +export const unix = (t: number): Dayjs => dayjsOriginal.unix(t).tz(); |
| 68 | +export const utc = dayjs.utc.bind(dayjs); |
| 69 | + |
| 70 | +dayjs.unix = unix; |
| 71 | +dayjs.extend = extend; |
| 72 | + |
| 73 | +export default dayjs; |
0 commit comments