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