Skip to content

Instantly share code, notes, and snippets.

@julioflima
Created September 5, 2020 05:46
Show Gist options
  • Save julioflima/d1ed7abe340ff5024a97ee45d1ee43c2 to your computer and use it in GitHub Desktop.
Save julioflima/d1ed7abe340ff5024a97ee45d1ee43c2 to your computer and use it in GitHub Desktop.
Rule, add a personalized date with moment timezone module.
const moment = require('moment-timezone');
module.exports = class SensorRule {
static date(req, res, next) {
try {
const { timestamp } = req.body;
const dateFull = new Date(timestamp).getTime();
const date = moment(dateFull).tz('UTC').format('YYYY/MM/DD HH:mm:ss.SSSSSSSSS');
req.body.date = date;
next();
} catch (error) {
res.send(error);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment