-/**
- * A bunch of shorthand to put together common parts of an HTML page.
- */
-
-/**
- * Some fields may have values outside normal dates, handle them here.
- * @param {Date} date
- * @param {String} otherwise
- */
-const dateOrNot = (date, otherwise) => {
- if (!date) {
- return otherwise;
- }
- if (typeof date === 'number') {
- date = new Date(date);
- }
- const dateMs = date.getTime();
- if (!Number.isFinite(dateMs)
- || dateMs == 0) {
- return otherwise;
- }
- return date.toString();
-};
-
-
-/**
- * Render a duration.
- * @param {Number} seconds
- * @returns {String}
- */
-const secondsToPeriod = (seconds) => {
- let value = seconds;
- const result = [];
-
- const nextResult = (factor, label) => {
- const r = factor ? value % factor : value;
- if (r) {
- result.push(`${r} ${label}${r != 1 ? 's' : ''}`);
- }
- value = factor ? Math.floor(value / factor) : value;
- }
-
- nextResult(60, 'second');
- nextResult(60, 'minute');
- nextResult(24, 'hour');
- nextResult(30, 'day');
- nextResult(undefined, 'month');
-
- result.reverse();
- return result.join(' ');
-};
-