mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 18:33:53 +00:00
ac0d5832b6
* install sass * refact: integration settings - OSC in its own HTTP endpoint - OSC settings have own object in db * refact: simplify event cycle * refact: restructure external triggers http * refact: restructure external triggers osc+socket * refact: restructure data updates * feat: osc integration class * IO improvements - timer uses osc integration - create trigger handler to manage external triggers * refact: refract state machine update * Integration: simple HTTP Client * Integration: http options in datamodel * Integration: call http send on life cycle * feat/62-logging: fix issue #71
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
const mts = 1000; // millis to seconds
|
|
const mtm = 1000 * 60; // millis to minutes
|
|
const mth = 1000 * 60 * 60; // millis to hours
|
|
|
|
/**
|
|
* @description Converts milliseconds to string representing time
|
|
* @param {number} ms - time in milliseconds
|
|
* @param {boolean} showSeconds - wether to show the seconds
|
|
* @param {string} delim - character between HH MM SS
|
|
* @param {string} ifNull - what to return if value is null
|
|
* @returns {string} String representing time 00:12:02
|
|
*/
|
|
|
|
export const stringFromMillis = (
|
|
ms,
|
|
showSeconds = true,
|
|
delim = ':',
|
|
ifNull = '...'
|
|
) => {
|
|
if (ms === null || isNaN(ms)) return ifNull;
|
|
const isNegative = ms < 0 ? '-' : '';
|
|
const millis = Math.abs(ms);
|
|
|
|
const showWith0 = (value) => (value < 10 ? `0${value}` : value);
|
|
const hours = showWith0(Math.floor(((millis / mth) % 60) % 24));
|
|
const minutes = showWith0(Math.floor((millis / mtm) % 60));
|
|
const seconds = showWith0(Math.floor((millis / mts) % 60));
|
|
|
|
return showSeconds
|
|
? `${isNegative}${
|
|
parseInt(hours) ? `${hours}${delim}` : `00${delim}`
|
|
}${minutes}${delim}${seconds}`
|
|
: `${isNegative}${parseInt(hours) ? `${hours}` : '00'}${delim}${minutes}`;
|
|
};
|
|
|
|
/**
|
|
* @description Converts an excel date to milliseconds
|
|
* @argument {string} excelDate - excel string date
|
|
* @returns {number} - time in millisenconds
|
|
*/
|
|
export const excelDateStringToMillis = (excelDate) => {
|
|
const date = new Date(excelDate);
|
|
if (date instanceof Date && !isNaN(date)) {
|
|
const h = date.getUTCHours();
|
|
const m = date.getMinutes();
|
|
const s = date.getSeconds();
|
|
|
|
return h * mth + m * mtm + s * mts;
|
|
}
|
|
return null;
|
|
};
|