Created
July 12, 2019 20:11
-
-
Save srl295/956e916b991b72d3eeed71ede6f8d996 to your computer and use it in GitHub Desktop.
slow and fast formats?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test Scaffold | |
const colors = { normal: x => process.stdout.write(x), bold: x => process.stdout.write('<b>'+x+'</b>') }; | |
const newline = () => console.log(); // starting to be a pattern here. | |
const obj = { builtAt: 0 }; | |
const fmt = new Intl.DateTimeFormat([], { | |
day: "2-digit", | |
month: "2-digit", | |
year: "numeric", | |
hour: "2-digit", | |
minute: "2-digit", | |
second: "2-digit" | |
}); | |
// https://github.com/webpack/webpack/blob/master/lib/Stats.js#L850 | |
const builtAtDate = new Date(obj.builtAt); | |
colors.normal("Built at: "); | |
for(const {type, value} of fmt.formatToParts(builtAtDate)) { | |
if(type === 'hour' || type === 'minute' || type === 'second') { | |
colors.bold(value); | |
} else { | |
colors.normal(value); | |
} | |
} | |
newline(); | |
// Built at: 1969-12-31 <b>16</b>:<b>00</b>:<b>00</b> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test Scaffold | |
const colors = { normal: x => process.stdout.write(x), bold: x => process.stdout.write('<b>'+x+'</b>') }; | |
const newline = () => console.log(); // starting to be a pattern here. | |
const obj = { builtAt: 0 }; | |
// https://github.com/webpack/webpack/blob/master/lib/Stats.js#L850 | |
const builtAtDate = new Date(obj.builtAt); | |
colors.normal("Built at: "); | |
colors.normal( | |
builtAtDate.toLocaleDateString(undefined, { | |
day: "2-digit", | |
month: "2-digit", | |
year: "numeric" | |
}) | |
); | |
colors.normal(" "); | |
colors.bold(builtAtDate.toLocaleTimeString()); | |
newline(); | |
// Built at: 1969-12-31 <b>16:00:00</b> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see: https://twitter.com/srl295/status/1149745866422534144