{ "version": 3, "sources": ["../javascripts/components/date-time/index.tsx", "../../../node_modules/date-fns/formatRelative.js"], "sourcesContent": ["import React, { useEffect, useState } from 'react';\n\nimport { format as dateFnsFormat, formatRelative } from 'date-fns';\nimport { nb, sv } from 'date-fns/locale';\nimport { getMarket } from '../../i18n';\n\nexport type DateTimeFormats = 0 | 1 | 2;\n\nexport const dateTimeFormat = {\n DateTime: 0 as DateTimeFormats,\n DateTimeString: 1 as DateTimeFormats,\n RelativeFromNow: 2 as DateTimeFormats,\n\n format: (\n value: string | number | Date,\n format: DateTimeFormats | undefined,\n marketCode: string,\n ) => {\n const currentLocale = marketCode === 'NO' ? nb : sv;\n\n switch (format) {\n case dateTimeFormat.DateTimeString:\n return dateFnsFormat(new Date(value), \"EEEE, d MMMM yyyy ', kl' HH:mm\", {\n locale: currentLocale,\n });\n case dateTimeFormat.RelativeFromNow:\n return formatRelative(new Date(value), new Date(), { locale: currentLocale });\n case dateTimeFormat.DateTime:\n return dateFnsFormat(new Date(value), 'd MMMM HH:mm', { locale: currentLocale });\n default:\n return dateFnsFormat(new Date(value), 'yyyy-MM-dd HH:mm', { locale: currentLocale });\n }\n },\n};\n\ninterface DateTimeProps {\n value: string | number | Date | null;\n format?: DateTimeFormats;\n className?: string;\n}\n\nconst DateTime = ({ value, format, className }: DateTimeProps) => {\n const marketCode = getMarket().marketCode;\n const [dateTimeOutput, setDateTimeOutput] = useState(null);\n useEffect(() => {\n if (value !== null) {\n setDateTimeOutput(dateTimeFormat.format(value, format, marketCode));\n }\n }, []);\n\n return dateTimeOutput ? {dateTimeOutput} : null;\n};\n\nexport default DateTime;\n", "import { defaultLocale } from \"./_lib/defaultLocale.js\";\nimport { getDefaultOptions } from \"./_lib/defaultOptions.js\";\nimport { normalizeDates } from \"./_lib/normalizeDates.js\";\nimport { differenceInCalendarDays } from \"./differenceInCalendarDays.js\";\nimport { format } from \"./format.js\";\n\n/**\n * The {@link formatRelative} function options.\n */\n\n/**\n * @name formatRelative\n * @category Common Helpers\n * @summary Represent the date in words relative to the given base date.\n *\n * @description\n * Represent the date in words relative to the given base date.\n *\n * | Distance to the base date | Result |\n * |---------------------------|---------------------------|\n * | Previous 6 days | last Sunday at 04:30 AM |\n * | Last day | yesterday at 04:30 AM |\n * | Same day | today at 04:30 AM |\n * | Next day | tomorrow at 04:30 AM |\n * | Next 6 days | Sunday at 04:30 AM |\n * | Other | 12/31/2017 |\n *\n * @param date - The date to format\n * @param baseDate - The date to compare with\n * @param options - An object with options\n *\n * @returns The date in words\n *\n * @throws `date` must not be Invalid Date\n * @throws `baseDate` must not be Invalid Date\n * @throws `options.locale` must contain `localize` property\n * @throws `options.locale` must contain `formatLong` property\n * @throws `options.locale` must contain `formatRelative` property\n *\n * @example\n * // Represent the date of 6 days ago in words relative to the given base date. In this example, today is Wednesday\n * const result = formatRelative(subDays(new Date(), 6), new Date())\n * //=> \"last Thursday at 12:45 AM\"\n */\nexport function formatRelative(date, baseDate, options) {\n const [date_, baseDate_] = normalizeDates(options?.in, date, baseDate);\n\n const defaultOptions = getDefaultOptions();\n const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale;\n const weekStartsOn =\n options?.weekStartsOn ??\n options?.locale?.options?.weekStartsOn ??\n defaultOptions.weekStartsOn ??\n defaultOptions.locale?.options?.weekStartsOn ??\n 0;\n\n const diff = differenceInCalendarDays(date_, baseDate_);\n\n if (isNaN(diff)) {\n throw new RangeError(\"Invalid time value\");\n }\n\n let token;\n if (diff < -6) {\n token = \"other\";\n } else if (diff < -1) {\n token = \"lastWeek\";\n } else if (diff < 0) {\n token = \"yesterday\";\n } else if (diff < 1) {\n token = \"today\";\n } else if (diff < 2) {\n token = \"tomorrow\";\n } else if (diff < 7) {\n token = \"nextWeek\";\n } else {\n token = \"other\";\n }\n\n const formatStr = locale.formatRelative(token, date_, baseDate_, {\n locale,\n weekStartsOn,\n });\n return format(date_, formatStr, { locale, weekStartsOn });\n}\n\n// Fallback for modularized imports:\nexport default formatRelative;\n"], "mappings": "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,KAAKD,CAAK,EAAG,mBAAoB,CAAE,OAAQG,CAAc,CAAC,CACvF,CACF,CACF,EAQMI,EAAW,CAAC,CAAE,MAAAP,EAAO,OAAAC,EAAQ,UAAAO,CAAU,IAAqB,CAChE,IAAMN,EAAaO,EAAU,EAAE,WACzB,CAACC,EAAgBC,CAAiB,KAAI,YAAwB,IAAI,EACxE,sBAAU,IAAM,CACVX,IAAU,MACZW,EAAkBZ,EAAe,OAAOC,EAAOC,EAAQC,CAAU,CAAC,CAEtE,EAAG,CAAC,CAAC,EAEEQ,EAAiB,EAAAE,QAAA,cAAC,QAAK,UAAWJ,GAAYE,CAAe,EAAU,IAChF,EAEOG,EAAQN", "names": ["import_react", "formatRelative", "date", "baseDate", "options", "date_", "baseDate_", "normalizeDates", "defaultOptions", "getDefaultOptions", "locale", "enUS", "weekStartsOn", "diff", "differenceInCalendarDays", "token", "formatStr", "format", "dateTimeFormat", "value", "format", "marketCode", "currentLocale", "nb", "sv", "formatRelative", "DateTime", "className", "getMarket", "dateTimeOutput", "setDateTimeOutput", "React", "date_time_default"] }