@webuildbots/webuildbots-sdk
Version:
webuildbots sdk
84 lines (83 loc) • 3.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Utils = void 0;
var sugar_1 = require("sugar");
var Utils = /** @class */ (function () {
function Utils() {
}
Utils.parseDate = function (formValue, languageCode, checkInputDate) {
sugar_1.Date.setLocale('en-GB');
var formats = [
'{weekday}? {dd}th of {month} {yy|yyyy}?',
'{weekday}? {dd}rd of {month} {yy|yyyy}?',
'{weekday}? {dd}st of {month} {yy|yyyy}?',
'{weekday}? {dd}nd of {month} {yy|yyyy}?',
'{weekday}? {dd}th {month} {yy|yyyy}?',
'{weekday}? {dd}rd {month} {yy|yyyy}?',
'{weekday}? {dd}st {month} {yy|yyyy}?',
'{weekday}? {dd}nd {month} {yy|yyyy}?',
'{weekday}? {month} {dd}th {yy|yyyy}?',
'{weekday}? {month} {dd}rd {yy|yyyy}?',
'{weekday}? {month} {dd}st {yy|yyyy}?',
'{weekday}? {month} {dd}nd {yy|yyyy}?',
'{dd} {MM} {yy}',
"{dd}st of the {MM}st {yy|yyyy}?",
"{dd}nd of the {MM}st {yy|yyyy}?",
"{dd}rd of the {MM}st {yy|yyyy}?",
"{dd}th of the {MM}st {yy|yyyy}?",
"{dd}st of the {MM}nd {yy|yyyy}?",
"{dd}nd of the {MM}nd {yy|yyyy}?",
"{dd}rd of the {MM}nd {yy|yyyy}?",
"{dd}th of the {MM}nd {yy|yyyy}?",
"{dd}st of the {MM}rd {yy|yyyy}?",
"{dd}nd of the {MM}rd {yy|yyyy}?",
"{dd}rd of the {MM}rd {yy|yyyy}?",
"{dd}th of the {MM}rd {yy|yyyy}?",
"{dd}st of the {MM}th {yy|yyyy}?",
"{dd}nd of the {MM}th {yy|yyyy}?",
"{dd}rd of the {MM}th {yy|yyyy}?",
"{dd}th of the {MM}th {yy|yyyy}?",
"{dd}st {MM}st {yy|yyyy}?",
"{dd}nd {MM}st {yy|yyyy}?",
"{dd}rd {MM}st {yy|yyyy}?",
"{dd}th {MM}st {yy|yyyy}?",
"{dd}st {MM}nd {yy|yyyy}?",
"{dd}nd {MM}nd {yy|yyyy}?",
"{dd}rd {MM}nd {yy|yyyy}?",
"{dd}th {MM}nd {yy|yyyy}?",
"{dd}st {MM}rd {yy|yyyy}?",
"{dd}nd {MM}rd {yy|yyyy}?",
"{dd}rd {MM}rd {yy|yyyy}?",
"{dd}th {MM}rd {yy|yyyy}?",
"{dd}st {MM}th {yy|yyyy}?",
"{dd}nd {MM}th {yy|yyyy}?",
"{dd}rd {MM}th {yy|yyyy}?",
"{dd}th {MM}th {yy|yyyy}?"
];
var loc = sugar_1.Date.getLocale('en-GB');
for (var _i = 0, formats_1 = formats; _i < formats_1.length; _i++) {
var format = formats_1[_i];
loc.addFormat(format);
}
var sugarOptions = {
locale: languageCode,
past: false,
future: false
};
if (checkInputDate) {
if (checkInputDate < 0) {
sugarOptions.past = true;
}
else if (checkInputDate > 0) {
sugarOptions.future = true;
}
else {
// defaults will be fine.
}
}
var date = new sugar_1.Date(sugar_1.Date.create(formValue, sugarOptions)).short('en-GB');
return date.raw;
};
return Utils;
}());
exports.Utils = Utils;