Created
August 1, 2024 16:41
-
-
Save paulwib/2706eaed1234797ea2f9edda22ff619c to your computer and use it in GitHub Desktop.
Generate lists of years, months and days
This file contains hidden or 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
import * as R from 'ramda'; | |
// Used for HTML form where you can select individual year, month and day from dropdowns | |
// Last 20 years in reverse order | |
const years: number[] = R.unfold( | |
(n: number) => n < new Date().getFullYear() - 20 || [n, n - 1], | |
new Date().getFullYear(), | |
); | |
// All the calendar months | |
const months: number[] = R.unfold( | |
(n: number) => | |
n > 11 ? false : [new Date(0, n).toLocaleString('en-US', { month: 'long' }), n + 1], | |
0, | |
); | |
// 31 days - tweaking the number of days based on month selected would require additional scripting | |
const days: number[] = R.unfold((n: number) => n > 31 || [n, n + 1], 1); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment