mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
YYYY-MM-DD HH:MM[:SS[.SSS]] support.
This commit is contained in:
parent
144092128c
commit
8261dd1e9a
@ -324,6 +324,8 @@ class Morris.Line
|
|||||||
n = date.match /^(\d+)-(\d+)$/
|
n = date.match /^(\d+)-(\d+)$/
|
||||||
o = date.match /^(\d+)-(\d+)-(\d+)$/
|
o = date.match /^(\d+)-(\d+)-(\d+)$/
|
||||||
p = date.match /^(\d+) W(\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+)?)$/
|
||||||
if m
|
if m
|
||||||
new Date(
|
new Date(
|
||||||
parseInt(m[1], 10),
|
parseInt(m[1], 10),
|
||||||
@ -347,6 +349,25 @@ class Morris.Line
|
|||||||
ret.setMonth(0, 1 + ((4 - ret.getDay()) + 7) % 7);
|
ret.setMonth(0, 1 + ((4 - ret.getDay()) + 7) % 7);
|
||||||
# add weeks
|
# add weeks
|
||||||
ret.getTime() + parseInt(p[2], 10) * 604800000
|
ret.getTime() + parseInt(p[2], 10) * 604800000
|
||||||
|
else if q
|
||||||
|
new Date(
|
||||||
|
parseInt(q[1], 10),
|
||||||
|
parseInt(q[2], 10) - 1,
|
||||||
|
parseInt(q[3], 10),
|
||||||
|
parseInt(q[4], 10),
|
||||||
|
parseInt(q[5], 10)).getTime()
|
||||||
|
else if r
|
||||||
|
secs = parseFloat(r[6])
|
||||||
|
isecs = Math.floor(secs)
|
||||||
|
msecs = Math.floor((secs - isecs) * 1000)
|
||||||
|
new Date(
|
||||||
|
parseInt(r[1], 10),
|
||||||
|
parseInt(r[2], 10) - 1,
|
||||||
|
parseInt(r[3], 10),
|
||||||
|
parseInt(r[4], 10),
|
||||||
|
parseInt(r[5], 10),
|
||||||
|
isecs,
|
||||||
|
msecs).getTime()
|
||||||
else
|
else
|
||||||
new Date(parseInt(date, 10), 0, 1)
|
new Date(parseInt(date, 10), 0, 1)
|
||||||
|
|
||||||
|
11
morris.js
11
morris.js
@ -356,12 +356,14 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Line.prototype.parseYear = function(date) {
|
Line.prototype.parseYear = function(date) {
|
||||||
var m, n, o, p, ret;
|
var isecs, m, msecs, n, o, p, q, r, ret, secs;
|
||||||
if (typeof date === 'number') return date;
|
if (typeof date === 'number') return date;
|
||||||
m = date.match(/^(\d+) Q(\d)$/);
|
m = date.match(/^(\d+) Q(\d)$/);
|
||||||
n = date.match(/^(\d+)-(\d+)$/);
|
n = date.match(/^(\d+)-(\d+)$/);
|
||||||
o = date.match(/^(\d+)-(\d+)-(\d+)$/);
|
o = date.match(/^(\d+)-(\d+)-(\d+)$/);
|
||||||
p = date.match(/^(\d+) W(\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+)?)$/);
|
||||||
if (m) {
|
if (m) {
|
||||||
return new Date(parseInt(m[1], 10), parseInt(m[2], 10) * 3 - 1, 1).getTime();
|
return new Date(parseInt(m[1], 10), parseInt(m[2], 10) * 3 - 1, 1).getTime();
|
||||||
} else if (n) {
|
} else if (n) {
|
||||||
@ -372,6 +374,13 @@
|
|||||||
ret = new Date(parseInt(p[1], 10), 0, 1);
|
ret = new Date(parseInt(p[1], 10), 0, 1);
|
||||||
if (ret.getDay() !== 4) ret.setMonth(0, 1 + ((4 - ret.getDay()) + 7) % 7);
|
if (ret.getDay() !== 4) ret.setMonth(0, 1 + ((4 - ret.getDay()) + 7) % 7);
|
||||||
return ret.getTime() + parseInt(p[2], 10) * 604800000;
|
return ret.getTime() + parseInt(p[2], 10) * 604800000;
|
||||||
|
} else if (q) {
|
||||||
|
return new Date(parseInt(q[1], 10), parseInt(q[2], 10) - 1, parseInt(q[3], 10), parseInt(q[4], 10), parseInt(q[5], 10)).getTime();
|
||||||
|
} else if (r) {
|
||||||
|
secs = parseFloat(r[6]);
|
||||||
|
isecs = Math.floor(secs);
|
||||||
|
msecs = Math.floor((secs - isecs) * 1000);
|
||||||
|
return new Date(parseInt(r[1], 10), parseInt(r[2], 10) - 1, parseInt(r[3], 10), parseInt(r[4], 10), parseInt(r[5], 10), isecs, msecs).getTime();
|
||||||
} else {
|
} else {
|
||||||
return new Date(parseInt(date, 10), 0, 1);
|
return new Date(parseInt(date, 10), 0, 1);
|
||||||
}
|
}
|
||||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user