Skip to content

Commit 8cf1953

Browse files
committed
feat: pad function
1 parent d3977f9 commit 8cf1953

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/lib/structures/Logger.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import EventEmitter from 'events';
44
import JSLogger, { ILogger, ILoggerOpts, ILogHandler, ILogLevel } from 'js-logger';
5+
import { Util } from '../util/Util';
56
import type { GlobalLogger } from 'js-logger';
67
import type { AutocompleteContext } from './contexts/AutocompleteContext';
78
import type { CommandContext } from './contexts/CommandContext';
@@ -69,7 +70,7 @@ export class LoggerClass extends EventEmitter implements GlobalLogger {
6970
if (ctx.level === JSLogger.ERROR) color = '\x1b[91m';
7071

7172
const date = new Date();
72-
messages[0] = `${color}[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}/${ctx.level.name}]\x1b[0m ${
73+
messages[0] = `${color}[${Util.pad(date.getHours())}:${Util.pad(date.getMinutes())}:${Util.pad(date.getSeconds())}/${ctx.level.name}]\x1b[0m ${
7374
messages[0]
7475
}`;
7576
},

src/lib/util/Util.ts

+4
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ export class Util {
9191
array = array.filter(item => typeof item === 'string');
9292
return `(${array.join(' -> ') || 'unknown'})`;
9393
}
94+
95+
static pad(number: number): string {
96+
return (number < 10 ? '0' : '') + number;
97+
}
9498
}

0 commit comments

Comments
 (0)