summaryrefslogtreecommitdiff
path: root/www
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
parent7a8a7f30f2fc809bc3d2faa8c28bde9dec342098 (diff)
date check
Diffstat (limited to 'www')
-rw-r--r--www/js/todo.js7
-rw-r--r--www/js/utils.js24
2 files changed, 11 insertions, 20 deletions
diff --git a/www/js/todo.js b/www/js/todo.js
index 23768b7..dd9acb1 100644
--- a/www/js/todo.js
+++ b/www/js/todo.js
@@ -32,7 +32,7 @@ var shows = null;
rh.ShowList = function(d) {
this.$this = $(this);
this.shows = [];
- if((Object.prototype.toString.call(d) !== '[object Date]') || (d.toString() === 'Invalid Date')) {
+ if(!is_valid_date(d)) {
this.current = new Date();
} else {
this.current = d;
@@ -59,8 +59,7 @@ rh.ShowList.prototype.fetch = function() {
self.$this.trigger('update');
}
}).fail(function() {
- if((Object.prototype.toString.call(self.last_succeeded) === '[object Date]') &&
- (self.last_succeeded.toString() !== 'Invalid Date')) {
+ if(is_valid_date(self.last_succeeded)) {
self.current = self.last_succeeded;
self.current_week = get_rd_week(self.current.valueOf());
self.$this.trigger('update');
@@ -178,7 +177,7 @@ function todo_init() {
var d = new Date();
if(url.path.length > 1) {
var tmp = new Date(url.path[1]);
- if((Object.prototype.toString.call(tmp) === '[object Date]') && (tmp.toString() !== 'Invalid Date')) {
+ if(is_valid_date(tmp)) {
d = tmp;
}
}
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()];