ReScript Date manipulation (formerly ReDate)

:wave: hello ReScript users!

Just wanted to let you know, that I have just released rescript-date (formerly known as ReDate, which has been already deprecated on NPM), you can find the Github repo here: https://github.com/mobily/rescript-date and the brand new docs site here: https://mobily.github.io/rescript-date/docs/.

Unfortunately, several date manipulation helpers are missing still (for instance: conversion and decade helpers), so contributions of any kind are welcome!

I’m looking forward to your feedback as well! :heart:

15 Likes

thanks for the notification.
It was an easy migration.

I’m just a bit bummed that it still uses |> instead of ->

That’s actually a very good point, I totally forgot that a pipe-forward operator has been deprecated (Pipe | ReScript Language Manual).
I have just published v2.0.0 (bumped up a major version since it might be a huge change for current users’ projects) with a pipe-first operator update.

Thanks a ton for your suggestion!

3 Likes

All good, working as expected
Thank you for the quick update :clap:

2 Likes

(Some comments)
What is the difference between lastDayOfWeek and endOfWeek​?
Is it an alias?
A lot of functions return a float when one would expect an int, is there a particular reason?
I didn’t found a function for returning a type Week.day from a given date (this is often a useful function.) There is Js.Date.getDay(example) == 4.0 but ReDate.getDay(example) == Tuesday would be more readable.
You provide ReDate.isSunday(date) functions for each day of the week, I would also expect a function like ReDate.isWeekday(date, Sunday) so that we could use a variable there. The function is there in src/ReDate_weekday.res, it only need to be exported with a proper api name.

How did you generate this html API doc? Did you use docusaurus? Isn’t there an equivalent than ocamldoc?
(In your html API documentation some lines are too long to be visible, IMHO you should break it in 2 lines to make something more readable.)

endOfWeek returns the last day of a week and the end of the day time, however, lastDayOfWeek does the same but it returns the start of the day time, so in two words, it’s a shortcut for:

date->ReDate.endOfWeek->ReDate.startOfDay

yes, a few ReDate functions were returning int type before v1 but I feel, in terms of improving the developer experience, it’s much easier to use ReDate, when it’s fully compatible with Js.Date (which expects float type) and other ReDate functions, so I would say the consistency is a good word in this case :slight_smile: take a look at the pseudo-code example below:

let today = Js.Date.make()

let fstDate = Js.Date.makeWithYMD(~year=2021., ~month=10., ~date=10., ())
let sndDate = Js.Date.makeWithYMD(~year=2021., ~month=10., ~date=1., ())

let diff = fstDate->ReDate.differenceInBusinessDays(sndDate)
// before v1 you had to use float_of_int
// today->ReDate.addDays(float_of_int(diff))
let date = today->ReDate.addDays(diff)

this sounds good to me! so obvious that getDay is often used by devs and it’s still missing in ReDate, I will add it for sure :slight_smile: (or, don’t you mind opening a new PR? :smirk:)
btw. you can see the current lib status here: https://mobily.github.io/rescript-date/docs/status

do you exactly mean the is function? https://github.com/mobily/rescript-date/blob/213cced4812ef7b30987ba78a666f2cbb1f06078/src/ReDate_utils.res#L80

yes, the documentation is built with docusaurus, I prefer using it to any other tool because I’m familiar with the tool (I have been using it in multiple projects), can customize things quickly and the generated site just looks good :sweat_smile:

yup, definitely you’re right :slight_smile: thanks for the suggestion, I will fix it :muscle: