UNPKG

1.46 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Jupyter Development Team.
3// Distributed under the terms of the Modified BSD License.
4var __importDefault = (this && this.__importDefault) || function (mod) {
5 return (mod && mod.__esModule) ? mod : { "default": mod };
6};
7Object.defineProperty(exports, "__esModule", { value: true });
8exports.Time = void 0;
9const moment_1 = __importDefault(require("moment"));
10/**
11 * The namespace for date functions.
12 */
13var Time;
14(function (Time) {
15 /**
16 * Convert a timestring to a human readable string (e.g. 'two minutes ago').
17 *
18 * @param value - The date timestring or date object.
19 *
20 * @returns A formatted date.
21 */
22 function formatHuman(value) {
23 moment_1.default.locale(document.documentElement.lang);
24 let time = moment_1.default(value).fromNow();
25 // FIXME-TRANS: This is not localization friendly!
26 time = time === 'a few seconds ago' ? 'seconds ago' : time;
27 return time;
28 }
29 Time.formatHuman = formatHuman;
30 /**
31 * Convert a timestring to a date format.
32 *
33 * @param value - The date timestring or date object.
34 *
35 * @param format - The format string.
36 *
37 * @returns A formatted date.
38 */
39 function format(value, timeFormat = 'YYYY-MM-DD HH:mm') {
40 return moment_1.default(value).format(timeFormat);
41 }
42 Time.format = format;
43})(Time = exports.Time || (exports.Time = {}));
44//# sourceMappingURL=time.js.map
\No newline at end of file