{"version":3,"file":"date-C2KZ8yVv.js","sources":["../../../../Coloplast.UI/src/shared/vanilla/date.js"],"sourcesContent":["/***************\r\n * Date Formatting - Using Intl.DateTimeFormat.\r\n ***************/\r\n\r\nlet cachedLocale;\r\nexport function getLocale(noCache = false) {\r\n\tif (!cachedLocale || noCache) {\r\n\t\tcachedLocale = document.documentElement.getAttribute('data-lang') || document.documentElement.getAttribute('lang') || \"en-US\";\r\n\t}\r\n\r\n\treturn cachedLocale;\r\n}\r\n\r\n/**\r\n * Capitalize the first letter of a string, while respecting the locale\r\n * @param {string} value\r\n * @return {string}\r\n */\r\nfunction capitalizeFirstLetter(value) {\r\n\treturn value.charAt(0).toLocaleUpperCase(getLocale()) + value.slice(1);\r\n}\r\n\r\n/**\r\n *\r\n * @param {Date|string} date\r\n * @return {number|Date}\r\n */\r\nfunction parseDate(date) {\r\n\treturn typeof date === \"string\" ? new Date(date) : date;\r\n}\r\n\r\n/**\r\n * Format a date in a fixed short date format, based on the locale\r\n * @example 5 Nov 2021\r\n * @param {Date|string} date\r\n * @param {string=} locale\r\n * @param {string=} timeZone\r\n * @return {string}\r\n */\r\nexport function formatShortDate(\r\n\tdate,\r\n\tlocale = getLocale(),\r\n\ttimeZone = undefined\r\n) {\r\n\tconst formatter = new Intl.DateTimeFormat(locale, {\r\n\t\tday: \"numeric\",\r\n\t\tmonth: \"short\",\r\n\t\tyear: \"numeric\",\r\n\t\ttimeZone,\r\n\t});\r\n\r\n\treturn formatter.format(parseDate(date));\r\n}\r\n\r\n/**\r\n * Format a date in a fixed long date format, based on the locale\r\n * @example Friday, 24 December 2021\r\n * @param {Date|string} date\r\n * @param {string=} locale\r\n * @param {string=} timeZone\r\n * @return {string}\r\n */\r\nexport function formatLongDate(\r\n\tdate,\r\n\tlocale = getLocale(),\r\n\ttimeZone = undefined\r\n) {\r\n\tconst formatter = new Intl.DateTimeFormat(locale, {\r\n\t\tday: \"numeric\",\r\n\t\tmonth: \"long\",\r\n\t\tyear: \"numeric\",\r\n\t\tweekday: \"long\",\r\n\t\ttimeZone,\r\n\t});\r\n\r\n\treturn capitalizeFirstLetter(\r\n\t\t// Since we most likely want to present the date standalone, we should have it capitalized. Otherwise the weekday might be presented in lowercase\r\n\t\tformatter.format(parseDate(date))\r\n\t);\r\n}\r\n\r\n/**\r\n * Format a date to time\r\n * @example 4:00 am\r\n * @param {Date|string} date\r\n * @param {string=} locale\r\n * @param {string=} timeZone\r\n * @return {string}\r\n */\r\nexport function formatTime(date, locale = getLocale(), timeZone = undefined) {\r\n\tconst formatter = new Intl.DateTimeFormat(locale, {\r\n\t\thour: \"numeric\",\r\n\t\tminute: \"2-digit\",\r\n\t\ttimeZone,\r\n\t});\r\n\r\n\treturn formatter.format(parseDate(date));\r\n}\r\n\r\n/**\r\n * Format a date with a custom set of DateTimeFormatOptions.\r\n * This allows you to fully customize the look of the result\r\n * @param {Date|string} date\r\n * @param {DateTimeFormatOptions} options\r\n * @param {string=} locale\r\n * @return {string}\r\n */\r\nexport function formatCustomDate(date, options, locale = getLocale()) {\r\n\tconst formatter = new Intl.DateTimeFormat(locale, options);\r\n\r\n\treturn formatter.format(parseDate(date));\r\n}\r\n"],"names":["cachedLocale","getLocale","noCache","capitalizeFirstLetter","value","parseDate","date","formatShortDate","locale","timeZone","formatLongDate","formatter","formatTime"],"mappings":"AAIA,IAAIA,EACG,SAASC,EAAUC,EAAU,GAAO,CAC1C,OAAI,CAACF,GAAgBE,KACpBF,EAAe,SAAS,gBAAgB,aAAa,WAAW,GAAK,SAAS,gBAAgB,aAAa,MAAM,GAAK,SAGhHA,CACR,CAOA,SAASG,EAAsBC,EAAO,CACrC,OAAOA,EAAM,OAAO,CAAC,EAAE,kBAAkBH,EAAW,CAAA,EAAIG,EAAM,MAAM,CAAC,CACtE,CAOA,SAASC,EAAUC,EAAM,CACxB,OAAO,OAAOA,GAAS,SAAW,IAAI,KAAKA,CAAI,EAAIA,CACpD,CAUO,SAASC,EACfD,EACAE,EAASP,EAAW,EACpBQ,EAAW,OACV,CAQD,OAPkB,IAAI,KAAK,eAAeD,EAAQ,CACjD,IAAK,UACL,MAAO,QACP,KAAM,UACN,SAAAC,CACF,CAAE,EAEgB,OAAOJ,EAAUC,CAAI,CAAC,CACxC,CAUO,SAASI,EACfJ,EACAE,EAASP,EAAW,EACpBQ,EAAW,OACV,CACD,MAAME,EAAY,IAAI,KAAK,eAAeH,EAAQ,CACjD,IAAK,UACL,MAAO,OACP,KAAM,UACN,QAAS,OACT,SAAAC,CACF,CAAE,EAED,OAAON,EAENQ,EAAU,OAAON,EAAUC,CAAI,CAAC,CAClC,CACA,CAUO,SAASM,EAAWN,EAAME,EAASP,EAAS,EAAIQ,EAAW,OAAW,CAO5E,OANkB,IAAI,KAAK,eAAeD,EAAQ,CACjD,KAAM,UACN,OAAQ,UACR,SAAAC,CACF,CAAE,EAEgB,OAAOJ,EAAUC,CAAI,CAAC,CACxC"}