@hebcal/core
Version:
A perpetual Jewish Calendar API
53 lines (51 loc) • 1.51 kB
JavaScript
/*! @hebcal/core v5.10.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
const hour12cc = {
US: 1,
CA: 1,
BR: 1,
AU: 1,
NZ: 1,
DO: 1,
PR: 1,
GR: 1,
IN: 1,
KR: 1,
NP: 1,
ZA: 1,
};
/**
* @private
* @param timeStr - original time like "20:30"
* @param suffix - "p" or "pm" or " P.M.". Add leading space if you want it
* @param options
*/
function reformatTimeStr(timeStr, suffix, options) {
var _a;
if (typeof timeStr !== 'string')
throw new TypeError(`Bad timeStr: ${timeStr}`);
const cc = ((_a = options === null || options === void 0 ? void 0 : options.location) === null || _a === void 0 ? void 0 : _a.getCountryCode()) || ((options === null || options === void 0 ? void 0 : options.il) ? 'IL' : 'US');
const hour12 = options === null || options === void 0 ? void 0 : options.hour12;
if (typeof hour12 !== 'undefined' && !hour12) {
return timeStr;
}
if (!hour12 && typeof hour12cc[cc] === 'undefined') {
return timeStr;
}
const hm = timeStr.split(':');
let hour = parseInt(hm[0], 10);
if (hour < 12 && suffix) {
suffix = suffix.replace('p', 'a').replace('P', 'A');
if (hour === 0) {
hour = 12;
}
}
else if (hour > 12) {
hour = hour % 12;
}
else if (hour === 0) {
hour = '00';
}
return `${hour}:${hm[1]}${suffix}`;
}
export { reformatTimeStr };
//# sourceMappingURL=reformatTimeStr.js.map