-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate-ext.js
40 lines (36 loc) · 1.34 KB
/
date-ext.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var monthNames = [ 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli',
'August', 'September', 'Oktober', 'November', 'Dezember' ];
var monthNamesShort = [ 'Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul',
'Aug', 'Sep', 'Okt', 'Nov', 'Dez' ];
function padDatePart(part) {
return (part < 10 ? '0' + part : part);
}
exports.toReadableDate = function(inputDate, formatType) {
if (inputDate.constructor != (new Date).constructor)
return '';
switch (formatType) {
case 'fullmonth':
var year = inputDate.getFullYear();
var month = monthNames[inputDate.getMonth()];
var day = inputDate.getDate();
return padDatePart(day) + '. ' + month + ' ' + year;
case 'datestamp':
var month = inputDate.getMonth() + 1;
var day = inputDate.getDate();
var hour = inputDate.getHours();
var min = inputDate.getMinutes();
var sec = inputDate.getSeconds();
return padDatePart(day) + '.' +
padDatePart(month) + ' @ ' +
padDatePart(hour) + ':' +
padDatePart(min) + ':' +
padDatePart(sec);
case 'timestamp':
var hour = inputDate.getHours();
var min = inputDate.getMinutes();
var sec = inputDate.getSeconds();
return padDatePart(hour) + ':' +
padDatePart(min) + ':' +
padDatePart(sec);
}
};