mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-08 18:11:45 -06:00
Merge pull request #40095 from rhillefeld/master
Added zero-padding to timestamp output
This commit is contained in:
commit
46506b5872
@ -2250,18 +2250,26 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function padLeft(s: string, length: number) {
|
||||
while (s.length < length) {
|
||||
s = " " + s;
|
||||
}
|
||||
return s;
|
||||
|
||||
/**
|
||||
* Returns string left-padded with spaces or zeros until it reaches the given length.
|
||||
*
|
||||
* @param s String to pad.
|
||||
* @param length Final padded length. If less than or equal to 's.length', returns 's' unchanged.
|
||||
* @param padString Character to use as padding (default " ").
|
||||
*/
|
||||
export function padLeft(s: string, length: number, padString: " " | "0" = " ") {
|
||||
return length <= s.length ? s : padString.repeat(length - s.length) + s;
|
||||
}
|
||||
|
||||
export function padRight(s: string, length: number) {
|
||||
while (s.length < length) {
|
||||
s = s + " ";
|
||||
}
|
||||
|
||||
return s;
|
||||
/**
|
||||
* Returns string right-padded with spaces until it reaches the given length.
|
||||
*
|
||||
* @param s String to pad.
|
||||
* @param length Final padded length. If less than or equal to 's.length', returns 's' unchanged.
|
||||
* @param padString Character to use as padding (default " ").
|
||||
*/
|
||||
export function padRight(s: string, length: number, padString: " " = " ") {
|
||||
return length <= s.length ? s : s + padString.repeat(length - s.length);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +57,6 @@ namespace ts.server {
|
||||
export function nowString() {
|
||||
// E.g. "12:34:56.789"
|
||||
const d = new Date();
|
||||
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
|
||||
return `${padLeft(d.getHours().toString(), 2, "0")}:${padLeft(d.getMinutes().toString(), 2, "0")}:${padLeft(d.getSeconds().toString(), 2, "0")}.${padLeft(d.getMilliseconds().toString(), 3, "0")}`;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user