Преглед изворни кода

Add date parsing function so things work in annoying browsers

master
Chris Smith пре 13 година
родитељ
комит
b6bf168977
1 измењених фајлова са 13 додато и 1 уклоњено
  1. 13
    1
      analyser.js

+ 13
- 1
analyser.js Прегледај датотеку

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
  * Gets a date object corresponding to the specified timestamp. If advanceToNext
60
  * Gets a date object corresponding to the specified timestamp. If advanceToNext
49
  * is specified, and the timestamp doesn't already correspond to the first of
61
  * is specified, and the timestamp doesn't already correspond to the first of
358
   var amounts = [];
370
   var amounts = [];
359
 
371
 
360
   $.each(this, function() {
372
   $.each(this, function() {
361
-   var time = new Date(this.Date.date).getTime();
373
+   var time = Date.parseYMD(this.Date.date);
362
    lastTime > 0 && differences.push(time - lastTime);
374
    lastTime > 0 && differences.push(time - lastTime);
363
    lastTime = time;
375
    lastTime = time;
364
    amounts.push(this.Amount);
376
    amounts.push(this.Amount);

Loading…
Откажи
Сачувај