globalgov / messydates

R package for Extended Date/Time Format (EDTF)
https://globalgov.github.io/messydates
Other
15 stars 1 forks source link

Add arithmetic functions for messy dates #9

Closed jhollway closed 2 years ago

henriquesposito commented 2 years ago

I have started to look into this issue, but I have a few questions.

  1. Do we need arithmetic functions?
  2. If so, will these be wrappers for some of the arithmetic functions in lubridate or new functions?
  3. What arithmetic functions should we add?

@jhollway and @jaeltan what do you think? Thank you!

jhollway commented 2 years ago

I think arithmetic functions such as the ability to add 3 days to a range of dates is important.

To start with, we might consider +, -, and maybe /?

henriquesposito commented 2 years ago

I have added arithmetic operations to add and subtract from messydates including ranges, negative dates, uncertain dates and sets of dates. @jhollway could you please take a look at the operate script in messydates and let me know if this is what you expected? Thank you.

jhollway commented 2 years ago

Thanks @henriquesposito, looks good. What I had in mind was to use the add/subtract operators, similar to in lubridate. Should be just a matter of setting some additional methods, and maybe reexporting the year(), month(), day() functions from {lubridate}?

henriquesposito commented 2 years ago

@jhollway Thank you for the feedback! I will try and adapt the code to use operators but still work with ranges, sets of dates, negative dates, and uncertain dates.

henriquesposito commented 2 years ago

As "messydt" is a character based class, binary operations with operators it become more complicated as we are dealing with both numeric (Date) class and messydt (character).

If we resolve the messydates before adding or subtracting a date or numeric values, there would be no issue at all and we could incorporate operators easily (we would not even need to set methods for these operations). However, this might defeat the purpose of adding operators as calculations for ranges and sets of dates would be impossible...

I am trying to, though, set methods for these operators that override base and allow for these operations. This will just take a bit more time than planned, but I think we can get there.

jhollway commented 2 years ago

Why not make the method first resolve/expand, then operate on the dates, and then convert/contract back into messydates?