|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let $fb18d541ea1ad717$var$formatterCache = new Map(); |
|
|
class $fb18d541ea1ad717$export$ad991b66133851cf { |
|
|
format(value) { |
|
|
return this.formatter.format(value); |
|
|
} |
|
|
formatToParts(value) { |
|
|
return this.formatter.formatToParts(value); |
|
|
} |
|
|
formatRange(start, end) { |
|
|
|
|
|
if (typeof this.formatter.formatRange === 'function') |
|
|
return this.formatter.formatRange(start, end); |
|
|
if (end < start) throw new RangeError('End date must be >= start date'); |
|
|
|
|
|
return `${this.formatter.format(start)} \u{2013} ${this.formatter.format(end)}`; |
|
|
} |
|
|
formatRangeToParts(start, end) { |
|
|
|
|
|
if (typeof this.formatter.formatRangeToParts === 'function') |
|
|
return this.formatter.formatRangeToParts(start, end); |
|
|
if (end < start) throw new RangeError('End date must be >= start date'); |
|
|
let startParts = this.formatter.formatToParts(start); |
|
|
let endParts = this.formatter.formatToParts(end); |
|
|
return [ |
|
|
...startParts.map((p)=>({ |
|
|
...p, |
|
|
source: 'startRange' |
|
|
})), |
|
|
{ |
|
|
type: 'literal', |
|
|
value: " \u2013 ", |
|
|
source: 'shared' |
|
|
}, |
|
|
...endParts.map((p)=>({ |
|
|
...p, |
|
|
source: 'endRange' |
|
|
})) |
|
|
]; |
|
|
} |
|
|
resolvedOptions() { |
|
|
let resolvedOptions = this.formatter.resolvedOptions(); |
|
|
if ($fb18d541ea1ad717$var$hasBuggyResolvedHourCycle()) { |
|
|
if (!this.resolvedHourCycle) this.resolvedHourCycle = $fb18d541ea1ad717$var$getResolvedHourCycle(resolvedOptions.locale, this.options); |
|
|
resolvedOptions.hourCycle = this.resolvedHourCycle; |
|
|
resolvedOptions.hour12 = this.resolvedHourCycle === 'h11' || this.resolvedHourCycle === 'h12'; |
|
|
} |
|
|
|
|
|
|
|
|
if (resolvedOptions.calendar === 'ethiopic-amete-alem') resolvedOptions.calendar = 'ethioaa'; |
|
|
return resolvedOptions; |
|
|
} |
|
|
constructor(locale, options = {}){ |
|
|
this.formatter = $fb18d541ea1ad717$var$getCachedDateFormatter(locale, options); |
|
|
this.options = options; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const $fb18d541ea1ad717$var$hour12Preferences = { |
|
|
true: { |
|
|
|
|
|
ja: 'h11' |
|
|
}, |
|
|
false: { |
|
|
} |
|
|
}; |
|
|
function $fb18d541ea1ad717$var$getCachedDateFormatter(locale, options = {}) { |
|
|
|
|
|
|
|
|
if (typeof options.hour12 === 'boolean' && $fb18d541ea1ad717$var$hasBuggyHour12Behavior()) { |
|
|
options = { |
|
|
...options |
|
|
}; |
|
|
let pref = $fb18d541ea1ad717$var$hour12Preferences[String(options.hour12)][locale.split('-')[0]]; |
|
|
let defaultHourCycle = options.hour12 ? 'h12' : 'h23'; |
|
|
options.hourCycle = pref !== null && pref !== void 0 ? pref : defaultHourCycle; |
|
|
delete options.hour12; |
|
|
} |
|
|
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : ''); |
|
|
if ($fb18d541ea1ad717$var$formatterCache.has(cacheKey)) return $fb18d541ea1ad717$var$formatterCache.get(cacheKey); |
|
|
let numberFormatter = new Intl.DateTimeFormat(locale, options); |
|
|
$fb18d541ea1ad717$var$formatterCache.set(cacheKey, numberFormatter); |
|
|
return numberFormatter; |
|
|
} |
|
|
let $fb18d541ea1ad717$var$_hasBuggyHour12Behavior = null; |
|
|
function $fb18d541ea1ad717$var$hasBuggyHour12Behavior() { |
|
|
if ($fb18d541ea1ad717$var$_hasBuggyHour12Behavior == null) $fb18d541ea1ad717$var$_hasBuggyHour12Behavior = new Intl.DateTimeFormat('en-US', { |
|
|
hour: 'numeric', |
|
|
hour12: false |
|
|
}).format(new Date(2020, 2, 3, 0)) === '24'; |
|
|
return $fb18d541ea1ad717$var$_hasBuggyHour12Behavior; |
|
|
} |
|
|
let $fb18d541ea1ad717$var$_hasBuggyResolvedHourCycle = null; |
|
|
function $fb18d541ea1ad717$var$hasBuggyResolvedHourCycle() { |
|
|
if ($fb18d541ea1ad717$var$_hasBuggyResolvedHourCycle == null) $fb18d541ea1ad717$var$_hasBuggyResolvedHourCycle = new Intl.DateTimeFormat('fr', { |
|
|
hour: 'numeric', |
|
|
hour12: false |
|
|
}).resolvedOptions().hourCycle === 'h12'; |
|
|
return $fb18d541ea1ad717$var$_hasBuggyResolvedHourCycle; |
|
|
} |
|
|
function $fb18d541ea1ad717$var$getResolvedHourCycle(locale, options) { |
|
|
if (!options.timeStyle && !options.hour) return undefined; |
|
|
|
|
|
|
|
|
locale = locale.replace(/(-u-)?-nu-[a-zA-Z0-9]+/, ''); |
|
|
locale += (locale.includes('-u-') ? '' : '-u') + '-nu-latn'; |
|
|
let formatter = $fb18d541ea1ad717$var$getCachedDateFormatter(locale, { |
|
|
...options, |
|
|
timeZone: undefined |
|
|
}); |
|
|
let min = parseInt(formatter.formatToParts(new Date(2020, 2, 3, 0)).find((p)=>p.type === 'hour').value, 10); |
|
|
let max = parseInt(formatter.formatToParts(new Date(2020, 2, 3, 23)).find((p)=>p.type === 'hour').value, 10); |
|
|
if (min === 0 && max === 23) return 'h23'; |
|
|
if (min === 24 && max === 23) return 'h24'; |
|
|
if (min === 0 && max === 11) return 'h11'; |
|
|
if (min === 12 && max === 11) return 'h12'; |
|
|
throw new Error('Unexpected hour cycle result'); |
|
|
} |
|
|
|
|
|
|
|
|
export {$fb18d541ea1ad717$export$ad991b66133851cf as DateFormatter}; |
|
|
|
|
|
|