datetimes
Version:
Extend class of Date
20 lines (17 loc) • 710 B
JavaScript
function HourExpression(dateRx, date, language) {
Expresion.call(this, dateRx, date, language);
this.oneDigit = oneDigit;
this.twoDigit = twoDigit;
this.threeDigit = null;
this.fourDigit = null;
this.otherDigit = null;
function oneDigit(input) {
var hour = this.date.toLocaleString('en-US', { hour: 'numeric', hour12: true});
hour = hour.replace(/ PM/g, '').replace(/ AM/g, '');
return input.replace(this.dateRx, hour.padStart(2, '0'));
}
function twoDigit(input) {
var hour = this.date.toLocaleString('en-US', { hour: 'numeric', hour12: false});
return input.replace(this.dateRx, hour.padStart(2, '0'));
}
}