Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/util/common/time.ts
13397 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
/**
7
* Used for representing seconds into a human readable string like 6 hours and 50 minutes.
8
* This is primarily used to represent how long to wait for a rate limit.
9
* @param seconds The number of seconds to convert to a human readable string.
10
* @returns A human readable string representing the number of seconds.
11
*/
12
export function secondsToHumanReadableTime(seconds: number): string {
13
if (seconds < 90) {
14
return `${seconds} seconds`;
15
}
16
17
const minutes = Math.floor(seconds / 60);
18
if (seconds <= 5400) {
19
return `${minutes} minutes`;
20
}
21
22
const hours = Math.floor(minutes / 60);
23
const remainingMinutes = minutes % 60;
24
25
let result = `${hours} hours`;
26
if (remainingMinutes > 0) {
27
result += ` ${remainingMinutes} minutes`;
28
}
29
30
return result;
31
}
32