Re: [Rd] round.Date and trunc.Date not working / implemented

2024-02-09 Thread Duncan Murdoch
On 08/02/2024 7:58 p.m., Jiří Moravec wrote: > This is a workaround, and could be the basis for a round.Date improvement: >   date <- Sys.Date() >   as.Date(round(as.POSIXct(date), "years")) >   as.Date(round(as.POSIXct(Sys.Date() + 180), "years")) > Duncan Murdoch That would work, per

Re: [Rd] round.Date and trunc.Date not working / implemented

2024-02-09 Thread Jiří Moravec
> This is a workaround, and could be the basis for a round.Date improvement: >   date <- Sys.Date() >   as.Date(round(as.POSIXct(date), "years")) >   as.Date(round(as.POSIXct(Sys.Date() + 180), "years")) > Duncan Murdoch That would work, perhaps structured similarly as `trunc.Date` is. The only

Re: [Rd] round.Date and trunc.Date not working / implemented

2024-02-09 Thread Jiří Moravec
Apologies then. I was using R version 4.1.2 (Bird Hippie) and looks like someone implemented a better trunc.Date version in the meantime. # v4.1.2 > trunc.Date function (x, ...) round(x - 0.499) # Unstable (2024-02-07 r85873) > trunc.Date function (x, units = c("secs", "mins", "hours", "d

Re: [Rd] round.Date and trunc.Date not working / implemented

2024-02-08 Thread Duncan Murdoch
This is a workaround, and could be the basis for a round.Date improvement: date <- Sys.Date() as.Date(round(as.POSIXct(date), "years")) as.Date(round(as.POSIXct(Sys.Date() + 180), "years")) Duncan Murdoch On 08/02/2024 12:23 p.m., Henrik Bengtsson wrote: Technically, there is a round()

Re: [Rd] round.Date and trunc.Date not working / implemented

2024-02-08 Thread Henrik Bengtsson
Technically, there is a round() for 'Date' objects, but it doesn't seem very useful, because it basically just fall back to the default round() method, which only takes the 'digits' argument. Here's an example: > date <- Sys.Date() > class(date) [1] "Date" We see that there are only two round()

Re: [Rd] round.Date and trunc.Date not working / implemented

2024-02-08 Thread Rui Barradas
Às 14:36 de 08/02/2024, Olivier Benz via R-devel escreveu: On 8 Feb 2024, at 15:15, Martin Maechler wrote: Jiří Moravec on Wed, 7 Feb 2024 10:23:15 +1300 writes: This is my first time working with dates, so if the answer is "Duh, work with POSIXt", please ignore it. Why is not `round

Re: [Rd] round.Date and trunc.Date not working / implemented

2024-02-08 Thread Aidan Lakshman
I just wanted to add some additional problems from trying to replicate this. `trunc` does indeed work as advertised here, as does calling `round.POSIXt(Sys.Date())` and `round(Sys.Date())`. These functions are definitely implemented. However, I am also able to replicate Jiří’s error: ``` > round

Re: [Rd] round.Date and trunc.Date not working / implemented

2024-02-08 Thread Olivier Benz via R-devel
> On 8 Feb 2024, at 15:15, Martin Maechler wrote: > >> Jiří Moravec >>on Wed, 7 Feb 2024 10:23:15 +1300 writes: > >> This is my first time working with dates, so if the answer is "Duh, work >> with POSIXt", please ignore it. > >> Why is not `round.Date` and `trunc.Date` "implement

Re: [Rd] round.Date and trunc.Date not working / implemented

2024-02-08 Thread Martin Maechler
> Jiří Moravec > on Wed, 7 Feb 2024 10:23:15 +1300 writes: > This is my first time working with dates, so if the answer is "Duh, work > with POSIXt", please ignore it. > Why is not `round.Date` and `trunc.Date` "implemented" for `Date`? > Is this because `Date` is (

[Rd] round.Date and trunc.Date not working / implemented

2024-02-07 Thread Jiří Moravec
This is my first time working with dates, so if the answer is "Duh, work with POSIXt", please ignore it. Why is not `round.Date` and `trunc.Date` "implemented" for `Date`? Is this because `Date` is (mostly) a virtual class setup for a better inheritance or is that something that is just missin