problem: incorrect reference time calculation

This commit is contained in:
Bob
2024-07-23 17:24:06 +08:00
parent b854895ff9
commit 3737e477d1
2 changed files with 26 additions and 4 deletions

View File

@@ -57,6 +57,25 @@ export function unixToRelativeTime(timestamp: number): string {
}
}
export function formatReferenceTime(hours: number) {
const totalMinutes = Math.round(hours * 60);
const wholeHours = Math.floor(totalMinutes / 60);
const remainingMinutes = totalMinutes % 60;
let result = '';
if (wholeHours > 0) {
result += `${wholeHours} hour${wholeHours > 1 ? 's' : ''}`;
}
if (remainingMinutes > 0) {
if (result.length > 0) result += ' and ';
result += `${remainingMinutes} minute${remainingMinutes > 1 ? 's' : ''}`;
}
return result || '0 minutes';
}
export async function getCuckPrice(): Promise<number | Error> {
try {
var url = 'https://api.coindesk.com/v1/bpi/currentprice.json';