summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
authorWu Cheng-Han2016-10-11 16:46:50 +0800
committerWu Cheng-Han2016-10-11 16:46:50 +0800
commitc06b2f483898669b224321728321b7a3a8e9e37c (patch)
tree24c7d3a6ecb19c074025fd9c24724393db013049 /public/js
parent4188d8f942867c27121d523a47899d726196213d (diff)
Fix history time should save in UNIX timestamp to avoid time offset issue
Diffstat (limited to '')
-rw-r--r--public/js/history.js13
1 files changed, 7 insertions, 6 deletions
diff --git a/public/js/history.js b/public/js/history.js
index 9be68104..324a9da2 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -96,8 +96,8 @@ function clearDuplicatedHistory(notehistory) {
var id = notehistory[i].id.replace(/\=+$/, '');
var newId = newnotehistory[j].id.replace(/\=+$/, '');
if (id == newId || notehistory[i].id == newnotehistory[j].id || !notehistory[i].id || !newnotehistory[j].id) {
- var time = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a');
- var newTime = moment(newnotehistory[j].time, 'MMMM Do YYYY, h:mm:ss a');
+ var time = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
+ var newTime = (typeof newnotehistory[i].time === 'number' ? moment(newnotehistory[i].time) : moment(newnotehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
if(time >= newTime) {
newnotehistory[j] = notehistory[i];
}
@@ -247,7 +247,7 @@ function renderHistory(view) {
return {
id: id,
text: title,
- time: moment().format('MMMM Do YYYY, h:mm:ss a'),
+ time: moment().valueOf(),
tags: tags
};
}
@@ -358,9 +358,10 @@ function parseToHistory(list, notehistory, callback) {
else if (notehistory && notehistory.length > 0) {
for (var i = 0; i < notehistory.length; i++) {
//parse time to timestamp and fromNow
- notehistory[i].timestamp = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').valueOf();
- notehistory[i].fromNow = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').fromNow();
- notehistory[i].time = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').format('llll');
+ var timestamp = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
+ notehistory[i].timestamp = timestamp.valueOf();
+ notehistory[i].fromNow = timestamp.fromNow();
+ notehistory[i].time = timestamp.format('llll');
if (notehistory[i].id && list.get('id', notehistory[i].id).length == 0)
list.add(notehistory[i]);
}