Hacker News new | past | comments | ask | show | jobs | submit login

To be fair most time libraries suck and can't handle fairly basic operations. For instance, if you're using python's datetime module and want to get the start/end dates of the current month, you need to "roll your own" like

    now = datetime.now()
    month_start = date(now.year, now.month, 1)
    month_end = date(now.year, now.month + 1, 1) - timedelta(days=1)





First result on google for “python's datetime module and want to get the start/end dates of the current month” shows a simple solution:

https://stackoverflow.com/questions/42950/get-the-last-day-o...


You should use: calendar.monthrange

You probably haven`t used phps Carbon.

So in Dec your code hits month 13? Kinda funny in a post how rolling your own time library is easy we made trivial bugs

That's the point. I'm not advocating rolling your own date logic, only pointing out how easy it is to for "roll your own" logic to make its way into code even if if you're using a datetime library.

Your solution is faulty.

aren't months zero-indexed?

If you're going to copy my code onto HN I would appreciate attribution.

/s




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: