123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- "use strict";
- exports.id = 76410;
- exports.ids = [76410];
- exports.modules = {
- /***/ 76410:
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
- /* harmony export */ "Bz": () => (/* binding */ dateToDateString),
- /* harmony export */ "Cl": () => (/* binding */ getCurrentMonth),
- /* harmony export */ "EP": () => (/* binding */ getTimezone),
- /* harmony export */ "OQ": () => (/* binding */ getMonthDateObject),
- /* harmony export */ "QH": () => (/* binding */ getCurrentDay),
- /* harmony export */ "Rp": () => (/* binding */ milliSecondsToSeconds),
- /* harmony export */ "S4": () => (/* binding */ numberToPaddedString),
- /* harmony export */ "SV": () => (/* binding */ getMonthsInYear),
- /* harmony export */ "ZC": () => (/* binding */ dateToReadableFormat),
- /* harmony export */ "Zu": () => (/* binding */ getFullDayName),
- /* harmony export */ "by": () => (/* binding */ secondsToReadableFormat),
- /* harmony export */ "fR": () => (/* binding */ makeDateRangeFromMonth),
- /* harmony export */ "pE": () => (/* binding */ secondsToMilliSeconds)
- /* harmony export */ });
- /* unused harmony exports secondsFormatter, getEarliestDate, parseDate, formatDateRelatively, dateToYearMonthDay, getFullMonthName */
- /* harmony import */ var _locale__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(24709);
- /* harmony import */ var _number__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(19303);
- // Converts seconds to (hours), minutes, and seconds
- const secondsFormatter = (seconds, locale)=>{
- if (!seconds || Number.isNaN(seconds)) {
- return "";
- }
- return new Date(seconds * 1000).toLocaleTimeString(getLangFullLocale(locale), {
- timeZone: "Etc/UTC",
- hour12: false,
- minute: "2-digit",
- second: "2-digit",
- ...seconds >= 3600 && {
- hour: "2-digit"
- }
- });
- };
- /**
- * Convert seconds to the format of `x hours, y minutes, z seconds`.
- * Or any combination of the three.
- *
- * @param {numbers} s seconds
- * @param {Translate} t translate function
- * @param {string} locale locale
- * @returns {string}
- */ // eslint-disable-next-line react-func/max-lines-per-function
- const secondsToReadableFormat = (s, t, locale)=>{
- const results = [];
- let seconds = s;
- let minutes = Math.floor(seconds / 60);
- const hours = Math.floor(minutes / 60);
- if (hours > 0) {
- results.push(t("reading-goal:x-hours", {
- count: hours,
- hours: (0,_locale__WEBPACK_IMPORTED_MODULE_0__/* .toLocalizedNumber */ .rQ)((0,_number__WEBPACK_IMPORTED_MODULE_1__/* .convertNumberToDecimal */ .uZ)(hours), locale)
- }));
- minutes %= 60;
- seconds %= 60;
- }
- if (minutes > 0) {
- results.push(t("reading-goal:x-minutes", {
- count: minutes,
- minutes: (0,_locale__WEBPACK_IMPORTED_MODULE_0__/* .toLocalizedNumber */ .rQ)((0,_number__WEBPACK_IMPORTED_MODULE_1__/* .convertNumberToDecimal */ .uZ)(minutes), locale)
- }));
- seconds %= 60;
- }
- // if there are seconds left, or if the duration is 0 (in this case, `results.length` = 0), add seconds
- if (seconds > 0 || results.length === 0) {
- results.push(t("reading-goal:x-seconds", {
- count: seconds,
- seconds: (0,_locale__WEBPACK_IMPORTED_MODULE_0__/* .toLocalizedNumber */ .rQ)((0,_number__WEBPACK_IMPORTED_MODULE_1__/* .convertNumberToDecimal */ .uZ)(seconds), locale)
- }));
- }
- return results.join(", ");
- };
- /**
- * Convert milliseconds to seconds.
- *
- * @param {number} milliSeconds
- * @returns {number}
- */ const milliSecondsToSeconds = (milliSeconds)=>milliSeconds / 1000;
- /**
- * Convert milliseconds to seconds.
- *
- * @param {number} seconds
- * @returns {number}
- */ const secondsToMilliSeconds = (seconds)=>seconds * 1000;
- /**
- * Get the earliest date of a groups of date string.
- *
- * @param {string[]} dates
- * @returns {number}
- */ const getEarliestDate = (dates)=>dates.map((dateString)=>parseDate(dateString)).sort((a, b)=>a - b)[0];
- /**
- * Parse a date string.
- *
- * @param {string} date
- * @returns {number}
- */ const parseDate = (date)=>Date.parse(date);
- /**
- * Format date to a string
- *
- * @param {Date} date
- * @param {string} locale
- * @returns {string} date
- */ const formatDateRelatively = (date, locale, now = new Date())=>{
- const fullLocale = LANG_LOCALE_MAP[locale];
- // Formatter for "Today" and "Yesterday" etc
- const relative = new Intl.RelativeTimeFormat(fullLocale, {
- numeric: "auto"
- });
- const nowDate = now.setHours(0, 0, 0, 0);
- const then = date.setHours(0, 0, 0, 0);
- const days = (then - nowDate) / 86400000;
- if (days < -365) {
- const years = Math.round(days / 365);
- return relative.format(years, "year");
- }
- if (days < -7) {
- const weeks = Math.round(days / 7);
- return relative.format(weeks, "weeks");
- }
- return relative.format(days, "day");
- };
- // Intl.DateTimeFormat is performance heavy so we are caching the formatter.
- let dateTimeFormatter = null;
- let timezone = null;
- /**
- * Returns the current timezone.
- *
- * @example `Europe/London`
- * @returns {string}
- */ const getTimezone = ()=>{
- if (timezone) return timezone;
- if (!dateTimeFormatter) dateTimeFormatter = new Intl.DateTimeFormat();
- timezone = dateTimeFormatter.resolvedOptions().timeZone;
- return timezone;
- };
- /**
- * Given a Date, return the year, month and day values
- *
- * @param {Date} date
- * @returns {{year: number, month: number, day: number}}
- */ const dateToYearMonthDay = (date)=>{
- const year = date.getFullYear();
- const month = date.getMonth() + 1;
- const day = date.getDate();
- return {
- year,
- month,
- day
- };
- };
- const getCurrentMonth = ()=>new Date().getMonth() + 1;
- const getCurrentDay = ()=>new Date().getDate();
- /**
- * Converts a date instance to a string in this format: YYYY-MM-DD
- *
- * @param {Date} date
- * @returns {string}
- */ const dateToDateString = (date)=>{
- const { year , month , day } = date instanceof Date ? dateToYearMonthDay(date) : date;
- return `${year}-${numberToPaddedString(month)}-${numberToPaddedString(day)}`;
- };
- /**
- * Gets the full day name in a given locale.
- * Example: `Monday` in `en`
- *
- * @param {Date} day
- * @param {string} locale
- * @returns {string}
- *
- */ const getFullDayName = (day, locale)=>{
- return day.toLocaleDateString(locale, {
- weekday: "long",
- timeZone: "UTC"
- });
- };
- /**
- * Gets the full month name in a given locale.
- * Example: `April` in `en`
- *
- * @param {Date} month
- * @param {string} locale
- * @returns {string}
- *
- */ const getFullMonthName = (month, locale)=>{
- return month.toLocaleDateString(locale, {
- month: "long",
- timeZone: "UTC"
- });
- };
- /**
- * Formats a date to a readable format.
- *
- * Example output: `Sunday, April 16`
- *
- * @param {Date | string} date Date instance or date string
- * @param {string} locale
- * @param {Intl.DateTimeFormatOptions} options
- * @returns {string}
- *
- */ const dateToReadableFormat = (date, locale, options = {})=>{
- const dateInstance = typeof date === "string" ? new Date(date) : date;
- return dateInstance.toLocaleDateString((0,_locale__WEBPACK_IMPORTED_MODULE_0__/* .getLangFullLocale */ .ic)(locale), {
- day: "numeric",
- month: "long",
- weekday: "long",
- timeZone: "UTC",
- ...options
- });
- };
- /**
- * Convert a number into a padded string with 0. E.g. 1 -> 01
- *
- * @param {number} number
- * @returns {string}
- */ const numberToPaddedString = (number)=>{
- return number.toString().padStart(2, "0");
- };
- /**
- * Given a month and a year, this function returns the first and last day of the month in format: YYYY-MM-DD.
- *
- * @param {number} month
- * @param {number} year
- * @returns {DateRange}
- */ const makeDateRangeFromMonth = (month, year)=>{
- const from = `${year}-${numberToPaddedString(month)}-01`;
- const to = `${year}-${numberToPaddedString(month)}-${numberToPaddedString(new Date(year, month, 0).getDate())}`;
- return {
- from,
- to
- };
- };
- /**
- * Get a Date out of year and month numbers.
- *
- * @param {year} year
- * @param {month} month
- * @returns {Date}
- */ const getMonthDateObject = (year, month)=>{
- return new Date(year, month, 0);
- };
- /**
- * This function returns an array of months in a given year.
- *
- * @param {number} year
- * @param {string} locale
- * @returns {Month[]}
- */ const getMonthsInYear = (year, locale)=>{
- const all = [];
- for(let i = 1; i <= 12; i += 1){
- const monthDate = getMonthDateObject(year, i);
- const daysInMonth = monthDate.getDate();
- all.push({
- id: i,
- name: getFullMonthName(monthDate, locale),
- daysCount: daysInMonth
- });
- }
- return all;
- };
- /***/ })
- };
- ;
- //# sourceMappingURL=76410.js.map
|