summaryrefslogtreecommitdiff
path: root/www/js/utils.js
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2017-01-14 14:05:45 (GMT)
committerChristian Pointner <equinox@helsinki.at>2017-01-14 14:06:33 (GMT)
commit77204deba25008b59dbf0f5387d0775c4f313d83 (patch)
tree381c4097121ef4ca55810f858e33c301aec5f72f /www/js/utils.js
parent7a8a7f30f2fc809bc3d2faa8c28bde9dec342098 (diff)
date check
Diffstat (limited to 'www/js/utils.js')
-rw-r--r--www/js/utils.js24
1 files changed, 8 insertions, 16 deletions
diff --git a/www/js/utils.js b/www/js/utils.js
index ae2ad0a..7bd5035 100644
--- a/www/js/utils.js
+++ b/www/js/utils.js
@@ -21,6 +21,10 @@
'use strict';
+function is_valid_date(d) {
+ return (Object.prototype.toString.call(d) === '[object Date]') && (d.toString() !== 'Invalid Date')
+}
+
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
@@ -55,20 +59,14 @@ monthname[11] = 'Dezember';
var monthname_short = new Array('Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez');
function format_date_iso(d) {
- if(Object.prototype.toString.call(d) !== '[object Date]') {
- return '-';
- }
- if (d.toString() === 'Invalid Date') {
+ if(!is_valid_date(d)) {
return '-';
}
return d.getFullYear() + '-' + Number(d.getMonth() + 1).pad(2) + '-' + Number(d.getDate()).pad(2);
}
function format_date(d) {
- if(Object.prototype.toString.call(d) !== '[object Date]') {
- return '-';
- }
- if (d.toString() === 'Invalid Date') {
+ if(!is_valid_date(d)) {
return '-';
}
var datestr = weekday_short[d.getDay()];
@@ -79,10 +77,7 @@ function format_date(d) {
}
function format_time(d) {
- if(Object.prototype.toString.call(d) !== '[object Date]') {
- return '-';
- }
- if (d.toString() === 'Invalid Date') {
+ if(!is_valid_date(d)) {
return '-';
}
var timestr = Number(d.getHours()).pad(2);
@@ -92,10 +87,7 @@ function format_time(d) {
}
function format_datetime(d) {
- if(Object.prototype.toString.call(d) !== '[object Date]') {
- return '-';
- }
- if (d.toString() === 'Invalid Date') {
+ if(!is_valid_date(d)) {
return '-';
}
var datetimestr = weekday_short[d.getDay()];