UNPKG

1.02 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.differenceInDays = differenceInDays;
7
8var _moment = require('moment');
9
10var _moment2 = _interopRequireDefault(_moment);
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14/**
15 * Get the difference between the start and the end time.
16 * For the countdown we need the days in absolute amounts, and the
17 * hours, minutes & seconds relative.
18 *
19 * If there is no end date passed in, we grab the current time.
20 *
21 * @param {String} start
22 * @param {String} end
23 * @return {Object}
24 */
25function differenceInDays(start, end) {
26 var startMoment = start ? (0, _moment2.default)(start) : (0, _moment2.default)();
27 var endMoment = (0, _moment2.default)(end);
28 var duration = _moment2.default.duration(startMoment.diff(endMoment));
29
30 return {
31 days: startMoment.diff(endMoment, 'days'),
32 hours: duration.hours(),
33 minutes: duration.minutes(),
34 seconds: duration.seconds()
35 };
36}
\No newline at end of file