Never Write Custom Date and Time Logic With AI

Time zones, leap years, and daylight saving time will break a hand-rolled date helper. Here's why you should let battle-tested libraries like date-fns, Day.js, or Temporal do the math instead.

Never Write Custom Date and Time Logic With AI

You should never write custom date and time logic with AI. Ever.

I know. It seems like simple math. Add a day, move the calendar forward, done. And AI can absolutely spit out a quick little helper function that looks correct. But that’s exactly the problem: it looks correct.

Why time is a nightmare in code

Time zones, leap years, and daylight saving time are an absolute nightmare in programming. Your helper might work perfectly on your laptop, in your time zone, on the day you tested it. Then someone in another country opens your app, or the clocks change, and suddenly the booking shows up on the wrong day or the reminder fires an hour late.

If you try to calculate all of that yourself, your app will break for users in other countries. It’s not a question of if.

Use a battle-tested date library instead

People have already mapped out pretty much every time anomaly on Earth and packaged it up for you. Lean on their work:

  • date-fns: a toolbox of small date functions.
  • Day.js: a lightweight library for parsing, formatting, and doing math with dates.
  • The Temporal API: the newer, built-in way JavaScript is getting to handle dates and times properly.

The good news

You don’t have to memorize any of these. Your AI coding agent already knows the syntax for all of them. So instead of asking it to “write a function that adds 7 days,” tell it which tool to use:

Use date-fns (not custom date math) to add 7 days to the user's
selected date, and keep the user's time zone in mind.

Same speed, way fewer 2am bug reports.

The takeaway

Vibe coding securely isn’t about writing everything yourself. It’s knowing which problems are already solved, and pointing your AI at the solution.

Want me to show you how to properly handle time zones in your app? Let me know, and for more vibe-code-securely tips, join my newsletter.

Happy building!

Kedasha

This post was written with the help of AI from a human-written YouTube script.

I write about building with AI.
Let's stay connected! 💕

Get the next post delivered to your inbox and follow me on Instagram for daily AI tips and coding content.

    See you on Instagram!