@enonic/mock-xp
Version:
Mock Enonic XP API JavaScript Library
58 lines (57 loc) • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalDateTime = void 0;
var LocalDateTime = (function () {
function LocalDateTime(value) {
this.belowMilli = 0;
if (typeof value === 'string') {
this.date = new Date(value);
var split = value.split('.');
if (split.length > 1) {
var sixString = split[1].replace(/\d{3}/, '').padEnd(6, '0');
this.belowMilli = parseInt(sixString);
}
}
else {
this.date = value;
}
}
LocalDateTime.prototype.getYear = function () {
return this.date.getFullYear();
};
LocalDateTime.prototype.getMonthValue = function () {
return this.date.getMonth() + 1;
};
LocalDateTime.prototype.getMonth = function () {
return LocalDateTime.months[this.date.getMonth()];
};
LocalDateTime.prototype.getDayOfMonth = function () {
return this.date.getDate();
};
LocalDateTime.prototype.getDayOfWeek = function () {
return LocalDateTime.daysOfWeek[this.date.getDay()];
};
LocalDateTime.prototype.getHour = function () {
return this.date.getHours();
};
LocalDateTime.prototype.getMinute = function () {
return this.date.getMinutes();
};
LocalDateTime.prototype.getSecond = function () {
return this.date.getSeconds();
};
LocalDateTime.prototype.getNano = function () {
return this.date.getMilliseconds() * 1000000 + this.belowMilli;
};
LocalDateTime.months = [
'JANUARY', 'FEBRUARY', 'MARCH', 'APRIL',
'MAY', 'JUNE', 'JULY', 'AUGUST',
'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'
];
LocalDateTime.daysOfWeek = [
'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY',
'FRIDAY', 'SATURDAY', 'SUNDAY'
];
return LocalDateTime;
}());
exports.LocalDateTime = LocalDateTime;