Selaa lähdekoodia

Add date parsing function so things work in annoying browsers

master
Chris Smith 13 vuotta sitten
vanhempi
commit
b6bf168977
1 muutettua tiedostoa jossa 13 lisäystä ja 1 poistoa
  1. 13
    1
      analyser.js

+ 13
- 1
analyser.js Näytä tiedosto

@@ -44,6 +44,18 @@ Date.prototype.getRangeText = function(other) {
44 44
  }
45 45
 }
46 46
 
47
+/**
48
+ * Parses a date string in the format YYYY-MM-DD HH:MM:SS.
49
+ *
50
+ * @param {String} input The input string
51
+ * @return {int} Number of milliseconds since 1970
52
+ */
53
+Date.parseYMD = function(input) {
54
+ var parts = input.split(/[:\-\s]/);
55
+ var date = new Date(parseInt(parts[0], 10), parseInt(parts[1], 10) - 1, parseInt(parts[2], 10), parseInt(parts[3], 10), parseInt(parts[4], 10), parseInt(parts[5], 10));
56
+ return date.getTime();
57
+}
58
+
47 59
 /**
48 60
  * Gets a date object corresponding to the specified timestamp. If advanceToNext
49 61
  * is specified, and the timestamp doesn't already correspond to the first of
@@ -358,7 +370,7 @@ function calculateRepeatTransactions(data) {
358 370
   var amounts = [];
359 371
 
360 372
   $.each(this, function() {
361
-   var time = new Date(this.Date.date).getTime();
373
+   var time = Date.parseYMD(this.Date.date);
362 374
    lastTime > 0 && differences.push(time - lastTime);
363 375
    lastTime = time;
364 376
    amounts.push(this.Amount);

Loading…
Peruuta
Tallenna