Date parsing and math

I’m looking for a date library for parsing/printing, adding offsets (days/months/years/month end flag), and modifying date components. I’m just concerned with dates, not times. Currently using Timedesc.Date, but it only has direct support for adding days. Ideally looking for something analogous to datetime.date and dateutil.relativedelta in Python world.

Thanks!

calendar has everything you want (and more)

2 Likes

I have found on opam several packages that might help you. In no particular order:

Which one you wind up choosing is ultimately up to you but after having a brief look at each I have a few unorganised remarks that may help you in your choice:

  • dates_calc is definitely on the leaner side with a more limited/minimal interface, so it might not be a match for complex requirements. On the other hand it also means the interface is easy to keep in mind.
  • odate also includes function for date & time. If, as your project evolves, you start needing time support, this might come in handy
  • calendar is owned, at least from what I can see on github, by the ocaml community organization and seems to be the most mature of these packages (260+ commits on github vs 50 for odate and 68 for dates_calc, although number of commits is admittedly not the most reliable metric). The test included in the repository also seems to be the most extensive of these 3 packages

Thanks! I think other than a month end concept (unless I missed it) this matches up.

I guess you can use days_in_month for this

Yep, will definitely need to handle with care. Looking at the coercion rules again, will need to check against rolling into the next month when adding months as well.