2017-01-31 07:50:28 +01:00
|
|
|
const Locale = require('./locale');
|
2015-10-17 23:49:24 +02:00
|
|
|
|
2017-01-31 07:50:28 +01:00
|
|
|
const Format = {
|
2015-10-17 23:49:24 +02:00
|
|
|
pad: function(num, digits) {
|
2017-01-31 07:50:28 +01:00
|
|
|
let str = num.toString();
|
2015-10-17 23:49:24 +02:00
|
|
|
while (str.length < digits) {
|
|
|
|
str = '0' + str;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
},
|
2016-06-04 10:31:06 +02:00
|
|
|
padStr: function(str, len) {
|
|
|
|
while (str.length < len) {
|
|
|
|
str += ' ';
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
},
|
2015-10-17 23:49:24 +02:00
|
|
|
dtStr: function(dt) {
|
2017-05-13 14:00:03 +02:00
|
|
|
if (typeof dt === 'number') {
|
|
|
|
dt = new Date(dt);
|
|
|
|
}
|
2019-08-16 23:05:39 +02:00
|
|
|
return dt
|
|
|
|
? this.dStr(dt) +
|
|
|
|
' ' +
|
|
|
|
this.pad(dt.getHours(), 2) +
|
|
|
|
':' +
|
|
|
|
this.pad(dt.getMinutes(), 2) +
|
|
|
|
':' +
|
|
|
|
this.pad(dt.getSeconds(), 2)
|
|
|
|
: '';
|
2015-10-17 23:49:24 +02:00
|
|
|
},
|
|
|
|
dStr: function(dt) {
|
2017-05-13 14:00:03 +02:00
|
|
|
if (typeof dt === 'number') {
|
|
|
|
dt = new Date(dt);
|
|
|
|
}
|
2015-12-17 19:25:25 +01:00
|
|
|
return dt ? dt.getDate() + ' ' + Locale.monthsShort[dt.getMonth()] + ' ' + dt.getFullYear() : '';
|
2016-06-11 16:18:11 +02:00
|
|
|
},
|
|
|
|
capFirst: function(str) {
|
2016-08-23 22:20:13 +02:00
|
|
|
if (!str) {
|
|
|
|
return '';
|
|
|
|
}
|
2016-06-11 16:18:11 +02:00
|
|
|
return str[0].toUpperCase() + str.substr(1);
|
2016-08-20 10:01:33 +02:00
|
|
|
},
|
|
|
|
dtStrFs: function(dt) {
|
2017-05-13 14:00:03 +02:00
|
|
|
if (typeof dt === 'number') {
|
|
|
|
dt = new Date(dt);
|
|
|
|
}
|
2019-08-16 23:05:39 +02:00
|
|
|
return dt
|
|
|
|
? dt.getFullYear() +
|
|
|
|
'-' +
|
|
|
|
this.pad(dt.getMonth() + 1, 2) +
|
|
|
|
'-' +
|
|
|
|
this.pad(dt.getDate(), 2) +
|
|
|
|
'T' +
|
|
|
|
this.pad(dt.getHours(), 2) +
|
|
|
|
'-' +
|
|
|
|
this.pad(dt.getMinutes(), 2) +
|
|
|
|
'-' +
|
|
|
|
this.pad(dt.getSeconds(), 2)
|
2016-08-20 10:01:33 +02:00
|
|
|
: '';
|
2015-10-17 23:49:24 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Format;
|