test-raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
1 lines • 2.45 kB
Source Map (JSON)
{"version":3,"sources":["../../src/common/date.ts"],"sourcesContent":["export type TimeStamp = string | number | Date;\n\nexport const isNumber = (val): boolean => typeof val === \"number\";\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 as number) * (options?.unit === \"s\" ? 1000 : 1)\n : timestampB;\n return new Date(timestampA).getTime() <= 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 as number) * (options?.unit === \"s\" ? 1000 : 1)\n : timestampB;\n return new Date(timestampA).getTime() > 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 ? offset.days * 24 * 60 * 60 * 1000 : 0) +\n (offset.hours ? offset.hours * 60 * 60 * 1000 : 0) +\n (offset.minutes ? offset.minutes * 60 * 1000 : 0) +\n (offset.seconds ? offset.seconds * 1000 : 0) +\n (offset.milliseconds ? offset.milliseconds : 0);\n return getDate(offsetedTimestamp);\n}\n"],"mappings":"AAEO,GAAM,GAAW,AAAC,GAAiB,MAAO,IAAQ,SAG5C,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,EACrC,EAAyB,mBAAS,QAAS,IAAM,IAAO,GACzD,EACJ,MAAO,IAAI,MAAK,CAAU,EAAE,QAAQ,GAAK,CAC3C,CAGO,WAAqB,EAAuB,EAAuB,EAA0C,CAClH,GAAM,GAAiB,EAAS,CAAU,EACrC,EAAyB,mBAAS,QAAS,IAAM,IAAO,GACzD,EACJ,MAAO,IAAI,MAAK,CAAU,EAAE,QAAQ,EAAI,CAC1C,CAEO,WACL,EACA,EAOM,CAEN,GAAM,GACJ,AAFgB,EAAQ,CAAQ,EAG/B,GAAO,KAAO,EAAO,KAAO,GAAK,GAAK,GAAK,IAAO,GAClD,GAAO,MAAQ,EAAO,MAAQ,GAAK,GAAK,IAAO,GAC/C,GAAO,QAAU,EAAO,QAAU,GAAK,IAAO,GAC9C,GAAO,QAAU,EAAO,QAAU,IAAO,GACzC,GAAO,aAAe,EAAO,aAAe,GAC/C,MAAO,GAAQ,CAAiB,CAClC","names":[]}