Path: blob/main/extensions/copilot/src/util/common/time.ts
13397 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45/**6* Used for representing seconds into a human readable string like 6 hours and 50 minutes.7* This is primarily used to represent how long to wait for a rate limit.8* @param seconds The number of seconds to convert to a human readable string.9* @returns A human readable string representing the number of seconds.10*/11export function secondsToHumanReadableTime(seconds: number): string {12if (seconds < 90) {13return `${seconds} seconds`;14}1516const minutes = Math.floor(seconds / 60);17if (seconds <= 5400) {18return `${minutes} minutes`;19}2021const hours = Math.floor(minutes / 60);22const remainingMinutes = minutes % 60;2324let result = `${hours} hours`;25if (remainingMinutes > 0) {26result += ` ${remainingMinutes} minutes`;27}2829return result;30}3132