{"version":3,"sources":["../../src/common/date.ts"],"sourcesContent":["export type TimeStamp = string | number | Date;\n\nexport const isNumber = (val: any): val is number => typeof val === \"number\";\n\nexport type DateParam = string | number | Date | undefined;\n\nexport const getDate = (value?: DateParam): Date => (value ? new Date(value) : new Date());\nexport const getTime = (value?: DateParam): number => getDate(value).getTime();\n\n/** A must be milliseconds */\nexport function isDateBefore(timestampA: TimeStamp, timestampB: TimeStamp, options?: { unit?: \"ms\" | \"s\" }): boolean {\n  const realTimestampB = isNumber(timestampB)\n    ? timestampB * (options?.unit === \"s\" ? 1000 : 1)\n    : getTime(timestampB);\n  return getTime(timestampA) <= realTimestampB;\n}\n\n/** A must be milliseconds */\nexport function isDateAfter(timestampA: TimeStamp, timestampB: TimeStamp, options?: { unit?: \"ms\" | \"s\" }): boolean {\n  const realTimestampB = isNumber(timestampB)\n    ? timestampB * (options?.unit === \"s\" ? 1000 : 1)\n    : getTime(timestampB);\n  return getTime(timestampA) > realTimestampB;\n}\n\nexport function offsetDateTime(\n  baseDate: DateParam,\n  offset: {\n    days?: number;\n    hours?: number;\n    minutes?: number;\n    seconds?: number;\n    milliseconds?: number;\n  },\n): Date {\n  const timestamp = getTime(baseDate);\n  const offsetedTimestamp =\n    timestamp +\n    (offset.days ?? 0) * 24 * 60 * 60 * 1000 +\n    (offset.hours ?? 0) * 60 * 60 * 1000 +\n    (offset.minutes ?? 0) * 60 * 1000 +\n    (offset.seconds ?? 0) * 1000 +\n    (offset.milliseconds ?? 0);\n  return getDate(offsetedTimestamp);\n}\n"],"mappings":"AAEO,GAAM,GAAW,AAAC,GAA4B,MAAO,IAAQ,SAIvD,EAAU,AAAC,GAA6B,EAAQ,GAAI,MAAK,CAAK,EAAI,GAAI,MACtE,EAAU,AAAC,GAA8B,EAAQ,CAAK,EAAE,QAAQ,EAGtE,WAAsB,EAAuB,EAAuB,EAA0C,CACnH,GAAM,GAAiB,EAAS,CAAU,EACtC,EAAc,mBAAS,QAAS,IAAM,IAAO,GAC7C,EAAQ,CAAU,EACtB,MAAO,GAAQ,CAAU,GAAK,CAChC,CAGO,WAAqB,EAAuB,EAAuB,EAA0C,CAClH,GAAM,GAAiB,EAAS,CAAU,EACtC,EAAc,mBAAS,QAAS,IAAM,IAAO,GAC7C,EAAQ,CAAU,EACtB,MAAO,GAAQ,CAAU,EAAI,CAC/B,CAEO,WACL,EACA,EAOM,CAlCR,cAoCE,GAAM,GACJ,AAFgB,EAAQ,CAAQ,EAG/B,MAAO,OAAP,OAAe,GAAK,GAAK,GAAK,GAAK,IACnC,MAAO,QAAP,OAAgB,GAAK,GAAK,GAAK,IAC/B,MAAO,UAAP,OAAkB,GAAK,GAAK,IAC5B,MAAO,UAAP,OAAkB,GAAK,IACvB,MAAO,eAAP,OAAuB,GAC1B,MAAO,GAAQ,CAAiB,CAClC","names":[]}