1
let offinsRecurs = [
moment("03-07-2018 8:00:00", "DD-MM-YYYY HH:mm:ss").recur().every(7).days(), //tuesday
moment("05-07-2018 15:00:00", "DD-MM-YYYY HH:mm:ss").recur().every(7).days(), //thursd
moment("06-07-2018 22:00:00", "DD-MM-YYYY HH:mm:ss").recur().every(7).days() //sat
];
let nextDatesOffin = offinsRecurs.map( recurDate => recurDate.fromDate(moment()).next(1) );
[ [ moment.utc("2018-07-10T8:00:00.000+00:00") ], // Next Tuesday
[ moment.utc("2018-07-12T15:00:00.000+00:00") ], // Next Thursday
[ moment.utc("2018-07-13T22:00:00.000+00:00") ] ] // Next Saturday

nextDatesOffin = offinsRecurs.map( recurDate => recurDate.fromDate(moment()).next(1)[0] );
let nextDateOffin = nextDatesOffin.reduce( (acc, elem) => Math.min(acc, elem), Infinity);
//moment(nextDateOffin)
//moment("2018-07-10T02:00:00.000")
//moment(nextDateOffin).fromNow()
//'in 3 days'
//console.log("Days:", nextDateOffin.days());
//console.log("H:", nextDateOffin.hours());
//console.log("M:", nextDateOffin.minutes());

let expiration = nextDateOffin
const now = moment();
const exp = moment(expiration);

console.log(exp.format());

days = exp.diff(now, 'days');
hours = exp.subtract(days, 'days').diff(now, 'hours');
minutes = exp.subtract(hours, 'hours').diff(now, 'minutes');

console.log(days, hours, minutes)

I am attempting to get remaining time from moment. e.g. 1D2H43M Remaining. All times need to be PDT. Wrote all of this, then realized it's in the wrong TZ. SO not to sure a way to get the proper TZ. This gives me the wrong remainder as well. Not sure if it is the TZ or the code here:

days = exp.diff(now, 'days');
hours = exp.subtract(days, 'days').diff(now, 'hours');
minutes = exp.subtract(hours, 'hours').diff(now, 'minutes');

0 Answers0