mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-20 13:06:48 +00:00
devex: show full time in dev log output
This commit is contained in:
@@ -42,11 +42,47 @@ class DAY extends TimeUnit {
|
||||
static value = 24 * HOUR;
|
||||
}
|
||||
|
||||
const module_epoch = Date.now();
|
||||
const module_epoch_d = new Date();
|
||||
|
||||
/**
|
||||
* Displays the current time in only the level of detail necessary based on
|
||||
* the time this module was loaded. i.e. If this module was loaded on
|
||||
* 2025-01-01 10:32:40, 5 minutes later this function would return "10:37:40",
|
||||
* one day later this function would return "02 10:32:40", and one month later
|
||||
* this function would return "02-01 10:32:40".
|
||||
* @param {*} now - current time as Date object
|
||||
*/
|
||||
const display_time = (now) => {
|
||||
const pad2 = n => String(n).padStart(2, "0");
|
||||
|
||||
const yyyy = now.getFullYear();
|
||||
const mm = pad2(now.getMonth() + 1);
|
||||
const dd = pad2(now.getDate());
|
||||
const HH = pad2(now.getHours());
|
||||
const MM = pad2(now.getMinutes());
|
||||
const SS = pad2(now.getSeconds());
|
||||
const time = `${HH}:${MM}:${SS}`;
|
||||
|
||||
const needYear = yyyy !== module_epoch_d.getFullYear();
|
||||
const needMonth = needYear || (now.getMonth() !== module_epoch_d.getMonth());
|
||||
const needDay = needMonth || (now.getDate() !== module_epoch_d.getDate());
|
||||
|
||||
if ( needYear ) return `${yyyy}-${mm}-${dd} ${time}`;
|
||||
if ( needMonth ) return `${mm}-${dd} ${time}`;
|
||||
if ( needDay ) return `${dd} ${time}`;
|
||||
return time; // same calendar day as first log
|
||||
};
|
||||
|
||||
|
||||
module.exports = {
|
||||
MILLISECOND,
|
||||
SECOND,
|
||||
MINUTE,
|
||||
HOUR,
|
||||
DAY,
|
||||
module_epoch,
|
||||
module_epoch_d,
|
||||
display_time,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user