@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 2.11 kB
Source Map (JSON)
{"version":3,"file":"date-helpers.mjs","names":[],"sources":["../../../../src/services/ai/helpers/date-helpers.ts"],"sourcesContent":["const dateKeyRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\n/** Adds calendar days in UTC so chart buckets remain stable across timezones. */\nexport const addDays = (date: Date, days: number) => {\n\tconst next = new Date(date);\n\tnext.setUTCDate(next.getUTCDate() + days);\n\treturn next;\n};\n\n/** Converts a Date to the YYYY-MM-DD bucket key used by usage chart responses. */\nexport const getDateKey = (date: Date) => date.toISOString().slice(0, 10);\n\n/** Parses a chart date key strictly so invalid input does not roll into a date. */\nexport const parseDateKey = (value: string) => {\n\tif (!dateKeyRegex.test(value)) return null;\n\n\tconst date = new Date(`${value}T00:00:00.000Z`);\n\tif (Number.isNaN(date.getTime())) return null;\n\treturn date;\n};\n\n/** Formats UTC dates for DB comparisons without relying on adapter-specific casts. */\nexport const formatDbTimestamp = (date: Date) =>\n\tdate.toISOString().slice(0, 19).replace(\"T\", \" \");\n\n/** Normalizes DB timestamp values so duration/chart logic can compare them safely. */\nexport const parseStoredTimestamp = (value: Date | string) => {\n\tif (value instanceof Date) return value;\n\n\tconst normalized = value.includes(\"T\") ? value : value.replace(\" \", \"T\");\n\tconst hasTimezone = /(?:Z|[+-]\\d{2}:?\\d{2})$/i.test(normalized);\n\treturn new Date(hasTimezone ? normalized : `${normalized}Z`);\n};\n"],"mappings":"AAAA,MAAM,EAAe,sBAGR,GAAW,EAAY,IAAiB,CACpD,IAAM,EAAO,IAAI,KAAK,CAAI,EAE1B,OADA,EAAK,WAAW,EAAK,WAAW,EAAI,CAAI,EACjC,CACR,EAGa,EAAc,GAAe,EAAK,YAAY,CAAC,CAAC,MAAM,EAAG,EAAE,EAG3D,EAAgB,GAAkB,CAC9C,GAAI,CAAC,EAAa,KAAK,CAAK,EAAG,OAAO,KAEtC,IAAM,EAAO,IAAI,KAAK,GAAG,EAAM,eAAe,EAE9C,OADI,OAAO,MAAM,EAAK,QAAQ,CAAC,EAAU,KAClC,CACR,EAGa,EAAqB,GACjC,EAAK,YAAY,CAAC,CAAC,MAAM,EAAG,EAAE,CAAC,CAAC,QAAQ,IAAK,GAAG,EAGpC,EAAwB,GAAyB,CAC7D,GAAI,aAAiB,KAAM,OAAO,EAElC,IAAM,EAAa,EAAM,SAAS,GAAG,EAAI,EAAQ,EAAM,QAAQ,IAAK,GAAG,EACjE,EAAc,2BAA2B,KAAK,CAAU,EAC9D,OAAO,IAAI,KAAK,EAAc,EAAa,GAAG,EAAW,EAAE,CAC5D"}