@@ -35,6 +35,36 @@ const getHumanSize = (bytes: number) => {
3535 return `${ ( bytes / 1.074e9 ) . toFixed ( 2 ) } GiB` ;
3636} ;
3737
38+ /**
39+ * Returns a string with seconds converted to human
40+ * readable time: hours, minutes, seconds
41+ */
42+ const getHumanTime = ( seconds : number ) : string => {
43+ seconds = Number ( seconds . toFixed ( 0 ) ) ;
44+
45+ if ( seconds < 60 ) {
46+ return `${ seconds } second${ seconds === 1 ? "" : "s" } ` ;
47+ }
48+
49+ if ( seconds < 3600 ) {
50+ const minutes = Math . floor ( seconds / 60 ) ;
51+ const remainder = seconds % 60 ;
52+
53+ return (
54+ `${ minutes } minute${ minutes === 1 ? "" : "s" } ` +
55+ `${ remainder > 0 ? `, ${ getHumanTime ( remainder ) } ` : "" } `
56+ ) ;
57+ }
58+
59+ const hours = Math . floor ( seconds / 3600 ) ;
60+ const remainder = seconds % 3600 ;
61+
62+ return (
63+ `${ hours } hour${ hours === 1 ? "" : "s" } ` +
64+ `${ remainder > 0 ? `, ${ getHumanTime ( remainder ) } ` : "" } `
65+ ) ;
66+ } ;
67+
3868/**
3969 * Generates a filename with unix timestamp in the scrast directory
4070 * creates the directory if it doesn't exist
@@ -49,4 +79,4 @@ const generateOutputFilename = () => {
4979 return `${ scrastDir } /${ Date . now ( ) } .mkv` ;
5080} ;
5181
52- export { getSeconds , getHumanSize , generateOutputFilename } ;
82+ export { getSeconds , getHumanSize , getHumanTime , generateOutputFilename } ;
0 commit comments