Browse Source

Merge pull request #2244 from almende/issue2015

improved data serialisation of timeline data
codeClimate
yotamberk 8 years ago
committed by GitHub
parent
commit
a3500f0d7c
2 changed files with 17 additions and 13 deletions
  1. +10
    -9
      examples/timeline/dataHandling/dataSerialization.html
  2. +7
    -4
      lib/util.js

+ 10
- 9
examples/timeline/dataHandling/dataSerialization.html View File

@ -35,12 +35,12 @@
<textarea id="data">
[
{"id": 1, "content": "item 1<br>start", "start": "2014-01-23"},
{"id": 2, "content": "item 2", "start": "2014-01-18"},
{"id": 3, "content": "item 3", "start": "2014-01-21"},
{"id": 4, "content": "item 4", "start": "2014-01-19", "end": "2014-01-24"},
{"id": 5, "content": "item 5", "start": "2014-01-28", "type": "point"},
{"id": 6, "content": "item 6", "start": "2014-01-26"}
{"id": 1, "content": "item 1", "start": "2014-01-01 01:00:00"},
{"id": 2, "content": "item 2", "start": "2014-01-01 02:00:00"},
{"id": 3, "content": "item 3", "start": "2014-01-01 03:00:00"},
{"id": 4, "content": "item 4", "start": "2014-01-01 04:00:00", "end": "2014-01-01 04:30:00"},
{"id": 5, "content": "item 5", "start": "2014-01-01 05:00:00", "type": "point"},
{"id": 6, "content": "item 6", "start": "2014-01-01 06:00:00"}
]
</textarea>
@ -89,9 +89,10 @@
function saveData() {
// get the data from the DataSet
//
// Note that we specify the output type of the fields start and end
// as ISODate, which is safely serializable. Other serializable types
// are Number (unix timestamp) or ASPDate.
// as "ISODate", which is safely serializable. Other serializable types
// are "Number" (unix timestamp), "ASPDate" or "String" (without timezone!).
//
// Alternatively, it is possible to configure the DataSet to convert
// the output automatically to ISODates like:
@ -118,4 +119,4 @@
loadData();
</script>
</body>
</html>
</html>

+ 7
- 4
lib/util.js View File

@ -392,8 +392,11 @@ exports.convert = function (object, type) {
case 'number':
case 'Number':
return Number(object.valueOf());
if (!isNaN(Date.parse(object))) {
return moment(object).valueOf();
} else {
return Number(object.valueOf());
}
case 'string':
case 'String':
return String(object);
@ -467,7 +470,7 @@ exports.convert = function (object, type) {
return new Date(Number(match[1])).toISOString(); // parse number
}
else {
return new Date(object).toISOString(); // parse string
return moment(object).format(); // ISO 8601
}
}
else {
@ -1477,4 +1480,4 @@ exports.getScrollBarWidth = function () {
document.body.removeChild (outer);
return (w1 - w2);
};
};

Loading…
Cancel
Save