diff options
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/todo.js | 7 | ||||
-rw-r--r-- | www/js/utils.js | 24 |
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()]; |