-
-
Notifications
You must be signed in to change notification settings - Fork 15
refactor: Date now handling #142
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,15 +80,15 @@ const submitData = (akey) => { | |
akey | ||
], (err, dbRes) => { | ||
let data; | ||
const now = parseInt(new Date() / 1000); | ||
const now = Math.floor(Date.now() / 1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
|
||
if (!err && dbRes && (data = dbRes[0])) { | ||
const socUpToDate = now < data.last_soc + 300; | ||
const locationUpToDate = now < data.last_location + 300; | ||
|
||
if (data.abrp && cars[data.car] && (data.soc_display || data.soc_bms) && socUpToDate) { | ||
const abrpData = { | ||
utc: new Date() / 1000, | ||
utc: now, | ||
soc: data.soc_display || data.soc_bms, | ||
speed: locationUpToDate ? data.gps_speed * 3.6 || 0 : 0, | ||
lat: locationUpToDate ? data.latitude : 0, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ const send = (req, res) => { | |
if (!err && dbRes && (userObj = dbRes[0]) != null) { | ||
// validate token | ||
if (userObj.token === req.body.token) { | ||
const now = parseInt(new Date() / 1000); | ||
const now = Math.floor(Date.now() / 1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
|
||
// valid, compare last_notification timestamp to determine if limit reached | ||
if ((userObj.last_notification || 0) + 60 < now) { | ||
|
@@ -80,4 +80,4 @@ const send = (req, res) => { | |
|
||
module.exports = { | ||
send | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,7 +232,7 @@ module.exports = { | |
qrStatus(req.query.code, (err, codeObj) => { | ||
if (!err && codeObj) { | ||
// prevent access if not charging or data is to old (older than 10 minutes) | ||
if (!codeObj.charging || (new Date() / 1000 - 600) > codeObj.last_soc) { | ||
if (!codeObj.charging || (Date.now() / 1000 - 600) > codeObj.last_soc) { | ||
res.status(401).json({ | ||
error: srv_errors.ACCESS_DENIED, | ||
debug: ((srv_config.DEBUG) ? codeObj : null) | ||
|
@@ -274,7 +274,7 @@ module.exports = { | |
let dbObj; | ||
|
||
if (!err && dbRes && (dbObj = dbRes[0])) { | ||
const now = parseInt(new Date() / 1000); | ||
const now = Math.floor(Date.now() / 1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
|
||
// valid, compare last_qr timestamp to determine if limit reached | ||
if ((dbObj.last_qr || 0) + 600 < now) { | ||
|
@@ -303,4 +303,4 @@ module.exports = { | |
} | ||
}); | ||
} | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ const srv_config = require('./../../srv_config.json'), | |
* @param {Function} callback callback function | ||
*/ | ||
const postSoC = (akey, socObj, callback) => { | ||
const now = parseInt(new Date() / 1000); | ||
const now = Math.floor(Date.now() / 1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
|
||
db.query('UPDATE sync SET soc_display=?, soc_bms=?, last_soc=? WHERE akey=?', [ | ||
socObj.display, socObj.bms, now, akey | ||
|
@@ -48,7 +48,7 @@ const getSoC = (akey, callback) => { | |
* @param {Function} callback callback function | ||
*/ | ||
const postExtended = (akey, extendedObj, callback) => { | ||
const now = parseInt(new Date() / 1000); | ||
const now = Math.floor(Date.now() / 1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
|
||
|
||
db.query('UPDATE sync SET soh=?, charging=?, rapid_charge_port=?, normal_charge_port=?, slow_charge_port=?, aux_battery_voltage=?, dc_battery_voltage=?, dc_battery_current=?, dc_battery_power=?,\ | ||
|
@@ -85,7 +85,7 @@ const getExtended = (akey, callback) => { | |
* @param {Function} callback callback function | ||
*/ | ||
const postLocation = (akey, locationObj, callback) => { | ||
const now = parseInt(new Date() / 1000); | ||
const now = Math.floor(Date.now() / 1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
|
||
db.query('UPDATE sync SET latitude=?, longitude=?, gps_speed=?, accuracy=?, location_timestamp=?, last_location=? WHERE akey=?', [ | ||
locationObj.latitude, locationObj.longitude, locationObj.speed, locationObj.accuracy, locationObj.timestamp, now, akey | ||
|
@@ -349,4 +349,4 @@ module.exports = { | |
} | ||
}); | ||
} | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').