Do the next 365 days include a 29 February or not ? Can be used also for: Is the year bissextile or not?

A year is bissextile if it has 366 days. Years that can be divided by 4 are bissextiles except for secular years (ends by 00) except each 400 years.

If you have a date in dt variable, just do ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366). 
It will tell you if  among the 12 months after this date, you had a 29 February:

> dt <- as.Date("2005-01-01")
ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366)
[1] 365
> dt <- as.Date("2008-01-01")
ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366)
[1] 366
> dt <- as.Date("2000-01-01")
ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366)
[1] 366
> dt <- as.Date("1900-01-01")
ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366)
[1] 365
> dt <- as.Date("1999-07-01")
ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366)
[1] 366
> dt <- as.Date("1999-07-20")
> ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366)
[1] 366
> dt <- as.Date("2000-02-29")
> ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366)
[1] 366
> dt <- as.Date("1999-02-28")
> ifelse(as.POSIXlt(dt+365)$mday==as.POSIXlt(dt)$mday, 365, 366)
[1] 365

Commentaires

Posts les plus consultés de ce blog

Standard error from Hessian Matrix... what can be done when problem occurs

stepAIC from package MASS with AICc

Install treemix in ubuntu 20.04