Fix 12hour format

This commit is contained in:
Eduard Kuzmenko 2022-04-19 22:39:03 +03:00
parent 1b02c41bcf
commit cff8e51a6c

View File

@ -526,13 +526,14 @@ namespace I18n {
let text: string;
if(this.options.hour && this.options.minute && Object.keys(this.options).length === 2/* && false */) {
text = ('0' + this.date.getHours()).slice(-2) + ':' + ('0' + this.date.getMinutes()).slice(-2);
let hours = this.date.getHours();
text = ('0' + (timeFormat === 'h12' ? (hours % 12) || 12 : hours)).slice(-2) + ':' + ('0' + this.date.getMinutes()).slice(-2);
// if(this.options.second) {
// text += ':' + ('0' + this.date.getSeconds()).slice(-2);
// }
if(timeFormat === 'h12') {
text += ' ' + (this.date.getHours() < 12 ? amPmCache.am : amPmCache.pm);
text += ' ' + (hours < 12 ? amPmCache.am : amPmCache.pm);
}
} else {
// * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle#adding_an_hour_cycle_via_the_locale_string