Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/util/date-time.ts
2500 views
1
/**
2
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
export function formatDate(date?: string) {
8
return date ? new Date(date).toLocaleString() : "";
9
}
10
11
export function formatHours(hours?: number) {
12
if (hours === undefined) {
13
return "";
14
}
15
const h = Math.floor(Math.abs(hours));
16
const rm = (Math.abs(hours) - h) * 60;
17
const m = Math.floor(rm);
18
const rs = (rm - m) * 60;
19
const s = Math.floor(rs);
20
const result = h + ":" + pad2(m) + ":" + pad2(s);
21
if (hours < 0) {
22
return `-${result}`;
23
} else {
24
return `${result}`;
25
}
26
}
27
28
function pad2(n: number) {
29
return n < 10 ? "0" + n : "" + n;
30
}
31
32