freeCodeCamp/server/utils/date-utils.js

12 lines
315 B
JavaScript
Raw Normal View History

import moment from 'moment-timezone';
// day count between two epochs (inclusive)
export function dayCount([head, tail], timezone = 'UTC') {
return Math.ceil(
moment(moment(head).tz(timezone).endOf('day')).tz(timezone).diff(
moment(tail).tz(timezone).startOf('day'),
2016-01-03 04:39:47 +00:00
'days',
true)
);
}