How to use the duration function from moment

Find comprehensive JavaScript moment.duration code examples handpicked from public code repositorys.

105
106
107
108
109
110
111
112
113
114
    if (chat) fs.writeJSONSync(file_path, chat);

    return chat;
}

const convertTimestamp = (timestamp) => moment.duration(timestamp, 'seconds')
                    .toISOString()
                    .replace(/P.*?T(?:(\d+?)H)?(?:(\d+?)M)?(?:(\d+).*?S)?/,
                        (_, ...ms) => {
                            const seg = v => v ? v.padStart(2, '0') : '00';
fork icon220
star icon0
watch icon32

149
150
151
152
153
154
155
156
157
// Remaining time
var remaining
if (torrent.done) {
        remaining = 'Done'
} else {
        remaining = moment.duration(torrent.timeRemaining / 1000, 'seconds').humanize()
        remaining = remaining[0].toUpperCase() + remaining.substring(1) + ' remaining'
}
$remaining.html(remaining)
fork icon138
star icon456
watch icon27

58
59
60
61
62
63
64
65
66
67

const printableTime = summary.publicationTime ? summary.publicationTime : moment();
const name = _.get(_.first(_.filter(_.get(summary, 'meaningfulId.local', []), { 'fblinktype': 'profile' })), 'text', null);
const hashtags = _.map(_.filter(_.get(summary, 'meaningfulId.local', []), { 'fblinktype': 'hashtag' }), function(lt) { return '#' + lt.hashtag });

/* const vdiff = summary.publicationTime ? "in " + moment.duration(
        moment(summary.impressionTime) - moment(summary.publicationTime) 
    ).humanize() : null; */
/*
const images = (summary.images && summary.images.count) ? `${summary.images.count} img` : null;
fork icon45
star icon107
watch icon37

+ 7 other calls in file

273
274
275
276
277
278
279
280
281
282
283
284


/**
 * Figures out what unit to format a set of ticks with
 */
function determineUnitForFormatting(ticks, minUnit, min, max) {
	var duration = moment.duration(moment(max).diff(moment(min)));
	var ilen = UNITS.length;
	var i, unit;


	for (i = ilen - 1; i >= UNITS.indexOf(minUnit); i--) {
fork icon0
star icon1
watch icon1

4
5
6
7
8
9
10
11
12
13
14
}


function getTimeInterval(startTime, endTime) {
  const start = moment(startTime, "HH:mm");
  const end = moment(endTime, "HH:mm");
  const interval = moment.duration(end.diff(start));
  const hours =
    interval.asHours() >= 0 ? interval.asHours() : interval.asHours() + 24;
  return hours;
}
fork icon0
star icon0
watch icon0