Merge pull request #1079 from Choromanski/feature/format-time-to-days

Format minutes now Days, Hours and Minutes
This commit is contained in:
Ajay Ramachandran 2021-12-11 19:39:28 -05:00 committed by GitHub
commit 7186829bc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -837,5 +837,13 @@
},
"fillerNewFeature": {
"message": "New! Skip tangents and jokes with the filler category. Enable in options"
},
"dayAbbreviation": {
"message": "d",
"description": "100d"
},
"hourAbbreviation": {
"message": "h",
"description": "100h"
}
}

View file

@ -731,16 +731,17 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
}
/**
* Converts time in minutes to 5h 25.1
* Converts time in minutes to 2d 5h 25.1
* If less than 1 hour, just returns minutes
*
* @param {float} minutes
* @returns {string}
*/
function getFormattedHours(minutes) {
minutes = Math.round(minutes * 10) / 10
const hours = Math.floor(minutes / 60);
return (hours > 0 ? hours + "h " : "") + (minutes % 60).toFixed(1);
minutes = Math.round(minutes * 10) / 10;
const days = Math.floor(minutes / 3600);
const hours = Math.floor(minutes / 60) % 24;
return (days > 0 ? days + chrome.i18n.getMessage("dayAbbreviation") + " " : "") + (hours > 0 ? hours + chrome.i18n.getMessage("hourAbbreviation") + " " : "") + (minutes % 60).toFixed(1);
}
//end of function