1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-16 19:10:54 +00:00
FrankerFaceZ/src/utilities/time.js
SirStendec 014eb203c3 The Great Webpack Update.
* Update to version 4 of webpack.
* For that matter, update *every dependency* to the latest available version.
* Remove the babel build target for Edge, as it doesn't seem to be necessary with webpack 4 and tenser.
* Add support for optional chaining and nullish coalescing via Babel transformations.
* Update the clips domain version to work better. Or at all, really.
* Remove unused code from i18n.
* Remove the last `<style>` from vue component files. They don't work that way now anyways.
* Fix a bug in Raven's report handler.
* Fix a bug with the menu button in browsers that don't understand `:scope` within `querySelector()`.
2019-06-19 20:57:14 -04:00

42 lines
No EOL
1.1 KiB
JavaScript

'use strict';
export function getBuster(resolution = 5) {
const now = Math.floor(Date.now() / 1000);
return now - (now % resolution);
}
export function duration_to_string(elapsed, separate_days, days_only, no_hours, no_seconds) {
const seconds = elapsed % 60;
let minutes = Math.floor(elapsed / 60),
hours = Math.floor(minutes / 60),
days = '';
minutes = minutes % 60;
if ( separate_days ) {
days = Math.floor(hours / 24);
hours = hours % 24;
if ( days_only && days > 0 )
return `${days} days`;
days = days > 0 ? `${days} days, ` : '';
}
const show_hours = (!no_hours || days || hours);
return `${days}${
show_hours ? `${days && hours < 10 ? '0' : ''}${hours}:` : ''
}${show_hours && minutes < 10 ? '0' : ''}${minutes}${
no_seconds ? '' : `:${seconds < 10 ? '0' : ''}${seconds}`}`;
}
export function print_duration(seconds) {
let minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
minutes %= 60;
seconds %= 60;
return `${hours > 0 ? `${hours}:${minutes < 10 ? '0' : ''}` : ''}${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
}