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

refactor: Date now handling #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MattiJarvinen
Copy link

@MattiJarvinen MattiJarvinen commented Sep 20, 2021

Use Math.floor to have timestamp (full second) values.
Use Date.now() to get milliseconds elapsed since the UNIX epoch.

parseInt has string parameter and calculation gives a number also most of the time creation of new Date object is unnecessary.

Use Math.floor to have timestamp (full second) values.
Use Date.now() to get milliseconds elapsed since the UNIX epoch.
@@ -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);
Copy link

Choose a reason for hiding this comment

The 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).

@@ -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);
Copy link

Choose a reason for hiding this comment

The 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).

@@ -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);
Copy link

Choose a reason for hiding this comment

The 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).

@@ -104,7 +104,7 @@ if (srv_config.ROOKOUT_TOKEN) rookout.start({token: srv_config.ROOKOUT_TOKEN});

// last activity track
app.use((req, res, next) => {
if (req.body.akey) db.query('UPDATE accounts SET lastactivity=? WHERE akey=?', [parseInt(new Date() / 1000), req.body.akey], () => next());
if (req.body.akey) db.query('UPDATE accounts SET lastactivity=? WHERE akey=?', [Math.floor(Date.now() / 1000), req.body.akey], () => next());
Copy link

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').

@@ -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);
Copy link

Choose a reason for hiding this comment

The 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).

@@ -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);
Copy link

Choose a reason for hiding this comment

The 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).

@@ -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);
Copy link

Choose a reason for hiding this comment

The 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant