[R-SIG-Finance] Re[R-sig-finance] lative Date Question
Jeff Ryan
jeff.a.ryan at gmail.com
Wed Mar 18 22:27:03 CET 2009
Sandy,
Somewhere in the quest to vectorize I must have left off some of the
leap year logic.
Thanks for catching this.
I will add to the next xts, and once I pass R CMD check will get up to CRAN.
For now:
lastof <-
function (year = 1970, month = 12, day = 31, hour = 23, min = 59, sec
= 59, tz = "")
{
mon.lengths <- c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
30, 31)
if (missing(day)) {
day <- ifelse(month %in% 2, ifelse(((year%%4 %in% 0 &
!year%%100 %in% 0) | (year%%400 %in% 0)), 29, 28),
mon.lengths[month])
}
if (length(c(year, month, day, hour, min, sec)) == 7 && c(year,
month, day, hour, min, sec) == c(1969, 12, 31, 23, 59,
59) && Sys.getenv("TZ") %in% c("", "GMT", "UTC"))
sec <- 58.9
ISOdatetime(year, month, day, hour, min, sec, tz)
}
> lastof(2000,1:12)
[1] "2000-01-31 23:59:59 GMT" "2000-02-29 23:59:59 GMT"
[3] "2000-03-31 23:59:59 GMT" "2000-04-30 23:59:59 GMT"
[5] "2000-05-31 23:59:59 GMT" "2000-06-30 23:59:59 GMT"
[7] "2000-07-31 23:59:59 GMT" "2000-08-31 23:59:59 GMT"
[9] "2000-09-30 23:59:59 GMT" "2000-10-31 23:59:59 GMT"
[11] "2000-11-30 23:59:59 GMT" "2000-12-31 23:59:59 GMT"
> lastof(2004,1:12)
[1] "2004-01-31 23:59:59 GMT" "2004-02-29 23:59:59 GMT"
[3] "2004-03-31 23:59:59 GMT" "2004-04-30 23:59:59 GMT"
[5] "2004-05-31 23:59:59 GMT" "2004-06-30 23:59:59 GMT"
[7] "2004-07-31 23:59:59 GMT" "2004-08-31 23:59:59 GMT"
[9] "2004-09-30 23:59:59 GMT" "2004-10-31 23:59:59 GMT"
[11] "2004-11-30 23:59:59 GMT" "2004-12-31 23:59:59 GMT"
> lastof(2003,1:12)
[1] "2003-01-31 23:59:59 GMT" "2003-02-28 23:59:59 GMT"
[3] "2003-03-31 23:59:59 GMT" "2003-04-30 23:59:59 GMT"
[5] "2003-05-31 23:59:59 GMT" "2003-06-30 23:59:59 GMT"
[7] "2003-07-31 23:59:59 GMT" "2003-08-31 23:59:59 GMT"
[9] "2003-09-30 23:59:59 GMT" "2003-10-31 23:59:59 GMT"
[11] "2003-11-30 23:59:59 GMT" "2003-12-31 23:59:59 GMT"
> lastof(1900,1:12)
[1] "1900-01-31 23:59:59 GMT" "1900-02-28 23:59:59 GMT"
[3] "1900-03-31 23:59:59 GMT" "1900-04-30 23:59:59 GMT"
[5] "1900-05-31 23:59:59 GMT" "1900-06-30 23:59:59 GMT"
[7] "1900-07-31 23:59:59 GMT" "1900-08-31 23:59:59 GMT"
[9] "1900-09-30 23:59:59 GMT" "1900-10-31 23:59:59 GMT"
[11] "1900-11-30 23:59:59 GMT" "1900-12-31 23:59:59 GMT"
R/Finance 2009
April 24 & 25, 2009 Chicago, IL, USA
http://www.RinFinance.com
EARLY REGISTRATION ENDS MARCH 31
--
Jeffrey Ryan
jeffrey.ryan at insightalgo.com
ia: insight algorithmics
www.insightalgo.com
More information about the R-SIG-Finance
mailing list