I have following code to get list of object with new timestamp. I am using momemt
lib to update time. Basic logic is to loop N times and collect list of times adding 1 min to each.
var moment = require('moment');
var _ = require('lodash');
var startDate = moment("1995-12-25");
var currentDate = startDate;
var result = _.range(5).map(function () {
const nextTimestamp = currentDate.add(60, 's');
console.log('nextTimestamp: ' + JSON.stringify(nextTimestamp));
currentDate = nextTimestamp;
return {
timestamp: nextTimestamp
}
});
console.log('result: ' + JSON.stringify(result, null, 2));
I am expecting it will give a array on timestamp with 1 min difference. The output I am seeing is:
nextTimestamp: "1995-12-25T06:01:00.000Z"
nextTimestamp: "1995-12-25T06:02:00.000Z"
nextTimestamp: "1995-12-25T06:03:00.000Z"
nextTimestamp: "1995-12-25T06:04:00.000Z"
nextTimestamp: "1995-12-25T06:05:00.000Z"
result: [
{
"timestamp": "1995-12-25T06:05:00.000Z"
},
{
"timestamp": "1995-12-25T06:05:00.000Z"
},
{
"timestamp": "1995-12-25T06:05:00.000Z"
},
{
"timestamp": "1995-12-25T06:05:00.000Z"
},
{
"timestamp": "1995-12-25T06:05:00.000Z"
}
]
Can anyone help me understand why array is coming with last timestamp for all array element.
Thanks.