Skip to content

Instantly share code, notes, and snippets.

@leomastoras
Created April 14, 2024 09:39
Show Gist options
  • Save leomastoras/d7482d88404f4dce9264b029110ee5cb to your computer and use it in GitHub Desktop.
Save leomastoras/d7482d88404f4dce9264b029110ee5cb to your computer and use it in GitHub Desktop.
Extends Date Object adding fancier collections
Object.assign(Date, {
emojiclocks: [11,...Array(23).keys()].map(c=>String.fromCodePoint(128336+c%12))
}, {
dayperiods: ` ${['',...
'evening afternoon morning night'
.split(/ /)].copyWithin(0,4).join(' ')} `
.replace(/\w+ /g, (w, i) => w.repeat(i / 7 + 3))
.match(/\w+/g)
.reverse()
.slice(1)
}, {
weekdays: ['', ...[...Array(7).keys()].map(weekday => new Date(2e3, 1, weekday).toLocaleString('en', ({
weekday: 'long'
})))]
}, {
months: ['', ...[...Array(12).keys()].map(month => new Date(2e3, month).toLocaleString('en', ({
month: 'long'
})))]
}, {
quarters: /../g [Symbol.match]
`thstndrd`.reduce((acc, itr, idx, arr) => ({
...acc,
[`q${++idx}`]: `${idx}${arr[(idx-20)%10] || arr[idx] || arr[0]} Quarter`
}), {})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment