Last active
April 18, 2024 23:39
-
-
Save loucyx/2ce2ff13c7e8318ce131d12edbc6154b to your computer and use it in GitHub Desktop.
Log only on programmer's day
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
/** | |
* Get current day number of the given date. | |
* | |
* @param now Target date (current date by default). | |
*/ | |
const dayNumber = (now = new Date()) => | |
Math.floor( | |
(now.getTime() - new Date(now.getFullYear(), 0, 0).getTime()) / 864e5, | |
); | |
// Usage: | |
const diff = 256 - dayNumber(); | |
console.log( | |
`${ | |
diff === 0 | |
? "It's international" | |
: `${diff} days ${diff > 0 ? `until` : `ago it was`}` | |
} programmer's day!`, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment