atcheck/lsscanner/new_ubuntu/node_modules/node-datetime/index.js

84 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-12-16 18:42:21 +01:00
'use strict';
var DateTime = require('./src/datetime');
var TimedNumber = require('./src/timednumber');
var TimedState = require('./src/timedstate');
// global offsets for datetime
var offsets = {
days: 0,
hours: 0
};
// global default format
var globalDefaultFormat = null;
exports.setOffsetInDays = function (d) {
if (isNaN(d)) {
throw new Error('invalidOffset');
}
offsets.days = d;
};
exports.setOffsetInHours = function (h) {
if (isNaN(h)) {
throw new Error('invalidOffset');
}
offsets.hours = h;
};
exports.setDefaultFormat = function (format) {
globalDefaultFormat = format;
};
exports.setWeekNames = function (list) {
DateTime.setWeekNames(list);
};
exports.setShortWeekNames = function (list) {
DateTime.setShortWeekNames(list);
};
exports.setMonthName = function (list) {
DateTime.setMonthName(list);
};
exports.setShortMonthNames = function (list) {
DateTime.setShortMonthName(list);
};
exports.setPeriod = function (list) {
DateTime.setPeriod(list);
};
exports.create = function (now, defaultFormat) {
if (!defaultFormat && globalDefaultFormat) {
defaultFormat = globalDefaultFormat;
}
var d = new DateTime(now, defaultFormat);
if (offsets.days !== 0) {
d.offsetInDays(offsets.days);
}
if (offsets.hours !== 0) {
d.offsetInHours(offsets.hours);
}
return d;
};
exports.createTimedNumber = function (conf) {
return new TimedNumber(conf);
};
exports.createTimedState = function (conf) {
return new TimedState(conf);
};