Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize Treatment, Entry and Device Status object dates to be all in UTC Strings #4658

Merged
merged 11 commits into from
Jul 17, 2019
Merged
Prev Previous commit
Next Next commit
Remove extra sorting based on date. Code clarifications
  • Loading branch information
sulkaharo committed Jun 17, 2019
commit 7f190f32b82e78b0707df653cfb125ad4e581130
3 changes: 0 additions & 3 deletions lib/api/devicestatus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ function configure (app, wares, ctx) {
q.count = 10;
}
ctx.devicestatus.list(q, function (err, results) {
results.sort(function(a,b){
return new Date(b.created_at) - new Date(a.created_at);
});
return res.json(results);
});
});
Expand Down
5 changes: 0 additions & 5 deletions lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ function configure(app, wares, ctx) {
});
return;
} else {

results.sort(function(a,b){
return new Date(b.created_at) - new Date(a.created_at);
});

return res.json(results);
}
});
Expand Down
2 changes: 0 additions & 2 deletions lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ function init(ctx) {
}
});

console.log("Plugins registered", enabledPlugins);

};

plugins.isPluginEnabled = function isPluginEnabled(pluginName) {
Expand Down
2 changes: 1 addition & 1 deletion lib/server/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function storage(env, ctx) {
docs.forEach(function(doc) {

// Normalize dates to be in UTC, store offset in utcOffset
var dateSource = doc.sysTime || doc.dateString || doc.date || new Date().getTime();
var dateSource = doc.dateString || doc.sysTime || doc.date || new Date().getTime();
var _sysTime = moment.parseZone(dateSource);
doc.utcOffset = _sysTime.utcOffset();
doc.sysTime = _sysTime.toISOString();
Expand Down
10 changes: 1 addition & 9 deletions lib/server/treatments.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,7 @@ function prepareData(obj) {

// Convert all dates to UTC dates

let d = moment();

try {
if (obj.created_at) d = moment.parseZone(obj.created_at);
} catch (error) {
console.error(error);
}

// Normalize all dates to UTC ISO strings
const d = moment(obj.created_at).isValid() ? moment(obj.created_at) : moment();
obj.created_at = d.toISOString();

var results = {
Expand Down