Created
April 14, 2024 09:39
-
-
Save leomastoras/d7482d88404f4dce9264b029110ee5cb to your computer and use it in GitHub Desktop.
Extends Date Object adding fancier collections
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
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