Skip to content

Instantly share code, notes, and snippets.

@srl295
Created July 12, 2019 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srl295/956e916b991b72d3eeed71ede6f8d996 to your computer and use it in GitHub Desktop.
Save srl295/956e916b991b72d3eeed71ede6f8d996 to your computer and use it in GitHub Desktop.
slow and fast formats?
// 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>
// 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>
@srl295
Copy link
Author

srl295 commented Jul 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment