Skip to content

Instantly share code, notes, and snippets.

@loucyx
Last active April 18, 2024 23:39
Show Gist options
  • Save loucyx/2ce2ff13c7e8318ce131d12edbc6154b to your computer and use it in GitHub Desktop.
Save loucyx/2ce2ff13c7e8318ce131d12edbc6154b to your computer and use it in GitHub Desktop.
Log only on programmer's day
/**
* 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