Better ISO date support

This commit is contained in:
Olly Smith 2012-03-23 19:09:15 +00:00
parent b3ab944aa8
commit 18b4191093
3 changed files with 9 additions and 9 deletions

View File

@ -82,7 +82,7 @@ class Morris.Line
# translate x labels into nominal dates
# note: currently using decimal years to specify dates
if @options.parseTime
@xvals = $.map @columnLabels, (x) => @parseYear x
@xvals = $.map @columnLabels, (x) => @parseDate x
else
@xvals = [(@columnLabels.length-1)..0]
# translate column labels, if they're timestamps
@ -370,15 +370,15 @@ class Morris.Line
tt.remove()
return ret
parseYear: (date) ->
parseDate: (date) ->
if typeof date is 'number'
return date
m = date.match /^(\d+) Q(\d)$/
n = date.match /^(\d+)-(\d+)$/
o = date.match /^(\d+)-(\d+)-(\d+)$/
p = date.match /^(\d+) W(\d+)$/
q = date.match /^(\d+)-(\d+)-(\d+) (\d+):(\d+)$/
r = date.match /^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+(\.\d+)?)$/
q = date.match /^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)Z?$/
r = date.match /^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)Z?$/
if m
new Date(
parseInt(m[1], 10),

View File

@ -83,7 +83,7 @@
}
if (this.options.parseTime) {
this.xvals = $.map(this.columnLabels, function(x) {
return _this.parseYear(x);
return _this.parseDate(x);
});
} else {
this.xvals = (function() {
@ -436,15 +436,15 @@
return ret;
};
Line.prototype.parseYear = function(date) {
Line.prototype.parseDate = function(date) {
var isecs, m, msecs, n, o, p, q, r, ret, secs;
if (typeof date === 'number') return date;
m = date.match(/^(\d+) Q(\d)$/);
n = date.match(/^(\d+)-(\d+)$/);
o = date.match(/^(\d+)-(\d+)-(\d+)$/);
p = date.match(/^(\d+) W(\d+)$/);
q = date.match(/^(\d+)-(\d+)-(\d+) (\d+):(\d+)$/);
r = date.match(/^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+(\.\d+)?)$/);
q = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)Z?$/);
r = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)Z?$/);
if (m) {
return new Date(parseInt(m[1], 10), parseInt(m[2], 10) * 3 - 1, 1).getTime();
} else if (n) {

2
morris.min.js vendored

File diff suppressed because one or more lines are too long