date/0000755000175100001440000000000014366211520011205 5ustar hornikusersdate/NAMESPACE0000644000175100001440000000122213224134363012422 0ustar hornikusersuseDynLib("date", .registration = TRUE) importFrom("graphics", "Axis", "axis", "par", "plot") export("as.date", "date.ddmmmyy", "date.mdy", "date.mmddyy", "date.mmddyyyy", "is.date", "mdy.date") S3method("Axis", "date") S3method("Math", "date") S3method("Ops", "date") S3method("Summary", "date") S3method("[", "date") S3method("[[", "date") S3method("as.Date", "date") S3method("as.POSIXct", "date") S3method("as.POSIXlt", "date") S3method("as.character", "date") S3method("as.data.frame", "date") S3method("as.vector", "date") S3method("is.na", "date") S3method("plot", "date") S3method("print", "date") S3method("summary", "date") date/ChangeLog0000644000175100001440000001620714366206044012772 0ustar hornikusers2023-01-31 Kurt Hornik * DESCRIPTION: New version is 1.2-42. * inst/CITATION: Drop. 2022-12-20 Kurt Hornik * DESCRIPTION: New version is 1.2-41. * src/char_date.c: Avoid sprintf(). 2022-10-07 Kurt Hornik * DESCRIPTION: New version is 1.2-40. * src/char_date.c: Add missing prototypes. 2020-02-05 Kurt Hornik * DESCRIPTION: New version is 1.2-39. * src/init.c: Typo in registration. 2018-01-06 Kurt Hornik * DESCRIPTION: New version is 1.2-38. * R/date.R: * NAMESPACE: Add and register as.Date(), as.POSIXct() and as.POSIXlt() methods for class 'date' previously provided in base. 2017-02-20 Kurt Hornik * DESCRIPTION: New version is 1.2-37. 2017-01-22 Kurt Hornik * R/date.R: * src/char_date.c: * src/init.c: Improve registration of native routines. 2017-01-17 Kurt Hornik * DESCRIPTION: New version is 1.2-36. * NAMESPACE: * R/date.R: * src/init.c: Register native routines. 2016-12-08 Kurt Hornik * DESCRIPTION: New version is 1.2-35. * inst/CITATION: Canonicalize CRAN URLs. 2016-01-06 Kurt Hornik * inst/CITATION: Avoid personList(). 2014-03-17 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-34. * NAMESPACE: Improve. 2012-11-23 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-33. * src/char_date.c (char_date): Try avoiding buffer overflow as suggested by Erik Doffagne . 2011-12-23 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-32. * R/date.R (summary.date): Sanitize handling of extra arguments. Spotted by Marina Saadia Otero . 2011-10-04 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-31. * R/date.R (as.vector.date): Coerce to numeric instead of character for mode = "any" so that pairs() can work. Suggested by Lasse Engbo Christiansen . (Axis.date): Added. Donated by Lasse Engbo Christiansen . 2011-09-18 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-30. * NAMESPACE: Added. 2009-10-20 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-29. * R/date.R (date.mdy): Fix nuisance spotted by David Bronaugh . 2009-09-10 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-28. * inst/CITATION: Improve. 2009-02-05 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-27. * inst/CITATION: Improve. 2007-12-24 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-26. * R/date.R (summary.date): Add ... so that na.rm can be used, Suggested by Steven McKinney . 2007-07-12 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-25. (License): Clarify. 2007-02-01 Kurt Hornik * inst/CITATION: Get date/year and version from the package metadata. 2006-12-19 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-23. * R/date.R (as.character.date): Add missing ... argument. 2006-09-29 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-22. * R/date.R: Fix invalid escapes. 2006-09-09 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-21. (Depends): Added. 2006-08-05 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-20. * man/as.date.Rd: Fix inconsistency spotted by Antony Unwin . 2006-06-26 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-19. * inst/CITATION: New file. 2004-06-09 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-18. (License): Change to GPL as permitted by Terry Therneau. 2004-01-31 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-17. * INDEX: Removed. * TITLE: Removed. 2003-08-06 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-16. * man/date.object.Rd: Remove usage for as.data() as this is documented (correctly) in 'as.date.Rd', and hence also the now unnecessary \synopsis. 2003-07-29 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-15. * R/date.R (print.date): print.atomic() is gone from R 1.8.0. Also, replace code repeated from as.character.date() by a call to it. 2003-07-28 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-14. * R/date.R (as.vector.date): Prototype has 'mode' and not 'type' as the second argument. 2003-04-23 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-13. (Author, Maintainer): Update KH email address. 2002-03-31 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-12. * INDEX: Rebuilt. * R/date.R (date.ddmmmyy, date.mmddyy, date.mmddyyyy): Be defensive about R 1.5.0 character NAs. 2001-11-27 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-11. * R/date.R: .Alias() is gone in R 1.4.0, hence remove. 2001-08-16 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-10. * R/date.R: Add missing `...' to print.date(). 2001-07-14 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-9. * man/date.ddmmmyy.Rd: Fix unbalanced braces. 2001-06-02 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-8. * man/date.object.Rd: Codoc fixes. 2001-03-24 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-7. * R/date.R: Add `PACKAGE' argument to FF calls. 2001-02-25 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-6. * R/date.R: Fix problem in mdy.date() reported by Alex McMillan . 2000-12-24 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-5. (Maintainer): New entry. Sun Jun 18 12:09:05 2000 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-4. * man/*.Rd: Add keyword `chron'. * man/is.date.Rd: Rename to `date.object.Rd'. Add \alias entries for methods for objects of class "date". Sat May 6 09:30:34 2000 Kurt Hornik * DESCRIPTION (Version): New version in 1.2-3. * R/date.R: Improved plot.date() (following suggestions by Uwe Ligges ). Sun May 2 01:32:48 1999 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-2. * R/date.R: New functions [[.date() and as.vector.date(). Sun Apr 25 12:08:41 1999 Kurt Hornik * DESCRIPTION (Version): New version is 1.2-1. date/man/0000755000175100001440000000000012213262741011760 5ustar hornikusersdate/man/date.mmddyy.Rd0000644000175100001440000000121611304021266014461 0ustar hornikusers\name{date.mmddyy} \alias{date.mmddyy} \title{Format a Julian date} \description{ Given a vector of Julian dates, this returns them in the form ``10/11/89'', ``28/7/54'', etc. } \usage{ date.mmddyy(sdate, sep = "/") } \arguments{ \item{sdate}{A vector of Julian dates, e.g., as returned by \code{mdy.date()}.} \item{sep}{Character string used to separate the month, day, and year portions of the returned string.} } \value{ A vector of character strings containing the formatted dates. } \seealso{ \code{\link{date.mdy}}, \code{\link{mdy.date}}, \code{\link{date.ddmmmyy}} } \examples{ date.mmddyy(as.date(10)) } \keyword{chron} date/man/date.mmddyyyy.Rd0000644000175100001440000000123511304021266015044 0ustar hornikusers\name{date.mmddyyyy} \alias{date.mmddyyyy} \title{Format a Julian date} \description{ Given a vector of Julian dates, this returns them in the form ``10/11/1989'', ``28/7/1854'', etc. } \usage{ date.mmddyyyy(sdate, sep = "/") } \arguments{ \item{sdate}{A vector of Julian dates, e.g., as returned by \code{mdy.date()}.} \item{sep}{Character string used to separate the month, day, and year portions of the returned string.} } \value{ A vector of character strings containing the formatted dates. } \seealso{ \code{\link{date.mdy}}, \code{\link{mdy.date}}, \code{\link{date.ddmmmyy}} } \examples{ date.mmddyyyy(as.date(1:10)) } \keyword{chron} date/man/date.mdy.Rd0000644000175100001440000000206111304021266013746 0ustar hornikusers\name{date.mdy} \alias{date.mdy} \title{Convert from Julian Dates to Month, Day, and Year} \description{ Convert a vector of Julian dates to a list of vectors with the corresponding values of month, day and year, and optionally weekday. } \usage{ date.mdy(sdate, weekday = FALSE) } \arguments{ \item{sdate}{a Julian date value, as returned by \code{mdy.date()}, number of days since 1/1/1960.} \item{weekday}{if \code{TRUE}, then the returned list also will contain the day of the week (Sunday=1, Saturday=7).} } \value{ A list with components \code{month}, \code{day}, and \code{year}. } \examples{ day <- 7 temp <- date.mdy(mdy.date(month = 7, day = day, year = 1960)) ## Check for illegal dates, such as 29 Feb in a non leap year if (temp$day != day) { cat("Some illegal dates\n") } else { cat("All days are legal\n") } } \references{ Press, W. H., Teukolsky, S. A., Vetterling, W. T., and Flannery, B. P. (1992). \emph{Numerical Recipes: The Art of Scientific Computing (Second Edition)}. Cambridge University Press. } \keyword{chron} date/man/date.object.Rd0000644000175100001440000000305311304021266014425 0ustar hornikusers\name{date.object} \alias{is.date} \alias{Math.date} \alias{Ops.date} \alias{Summary.date} \alias{[.date} \alias{[[.date} \alias{as.character.date} \alias{as.data.frame.date} \alias{as.vector.date} \alias{is.na.date} \alias{plot.date} \alias{print.date} \alias{summary.date} \title{Date Objects} \description{ Objects of class \code{"date"}. } \usage{ is.date(x) } \arguments{ \item{x}{any R object.} } \details{ Dates are stored as the number of days since 1/1/1960, and are kept in integer format. (This is the same baseline value as is used by SAS). The numerical methods for dates treat \code{date - date} as a numeric, and \code{date +- numeric} as a date. \code{is.date} returns \code{TRUE} if \code{x} has class \code{"date"}, and \code{FALSE} otherwise. Its behavior is unaffected by any attributes of \code{x}; for example, \code{x} could be a date array (in contrast to the behavior of \code{is.vector}). \code{as.date} returns \code{x} if \code{x} is a simple object of class \code{"date"}, and otherwise a date vector of the same length as \code{x} and with data resulting from coercing the elements of \code{x} to class \code{"date"}. See the manual page for \code{as.date()} for details. Logical operations as well as the numeric functions \code{exp()}, \code{log()}, and so on are invalid. Other methods exist for missing value, \code{as.character()}, printing, and summarizing. } \seealso{ \code{\link{date.mdy}}, \code{\link{mdy.date}}, \code{\link{date.ddmmmyy}}, \code{\link{as.date}}. } \keyword{chron} date/man/date.ddmmmyy.Rd0000644000175100001440000000076211304021266014643 0ustar hornikusers\name{date.ddmmmyy} \alias{date.ddmmmyy} \title{Format a Julian date} \description{ Given a vector of Julian dates, this returns them in the form ``10Nov89'', ``28Jul54'', etc. } \usage{ date.ddmmmyy(sdate) } \arguments{ \item{sdate}{A vector of Julian dates, e.g., as returned by \code{mdy.date()}.} } \value{ A vector of character strings containing the formatted dates. } \seealso{ \code{\link{mdy.date}}, \code{\link{date.mdy}} } \examples{ date.ddmmmyy(1:10) } \keyword{chron} date/man/mdy.date.Rd0000644000175100001440000000345111304021266013752 0ustar hornikusers\name{mdy.date} \alias{mdy.date} \title{Convert to Julian Dates} \description{ Given a month, day, and year, returns the number of days since January 1, 1960. } \usage{ mdy.date(month, day, year, nineteen = TRUE, fillday = FALSE, fillmonth = FALSE) } \arguments{ \item{month}{vector of months.} \item{day}{vector of days.} \item{year}{vector of years.} \item{nineteen}{if \code{TRUE}, year values between 0 and 99 are assumed to be in the 20th century A.D.; otherwise, if \code{FALSE}, they are assumed to be in the 1st century A.D.} \item{fillday}{if \code{TRUE}, then missing days are replaced with 15.} \item{fillmonth}{if \code{TRUE}, then a missing month causes the month and day to be set to 7/1.} } \value{ a vector of Julian dates. } \details{ The date functions are particularly useful in computing time spans, such as number of days on test, and similar functions can be found in other statistical packages. The baseline date of Jan 1, 1960 is, of course, completely arbitrary (it is the same one used by SAS). The \code{fillday} and \code{fillmonth} options are perhaps useful only to the author and a very few others: we sometimes deal with patients whose birth date was in the 1800's, and only the month or even only the year is known. When the interval is greater than 80 years, a filler seems defensible. } \references{ Press, W. H., Teukolsky, S. A., Vetterling, W. T., and Flannery, B. P. (1992). \emph{Numerical Recipes: The Art of Scientific Computing (Second Edition)}. Cambridge University Press. } \seealso{ \code{\link{date.mmddyy}}, \code{\link{date.ddmmmyy}}, \code{\link{date.mmddyyyy}} } \examples{ mdy.date(3, 10, 53) xzt <-1:10 xzy <- as.date(xzt) test <- data.frame(x = xzt, date = xzy) summary(test) } \keyword{chron} date/man/as.date.Rd0000644000175100001440000000222611304021266013563 0ustar hornikusers\name{as.date} \alias{as.date} \title{Coerce Data to Dates} \description{ Converts any of the following character forms to a Julian date: 8/31/56, 8-31-1956, 31 8 56, 083156, 31Aug56, or August 31 1956. } \usage{ as.date(x, order = "mdy", ...) } \arguments{ \item{x}{input data vector.} \item{order}{if \code{x} is character, defines the order in which the terms are assumed to appear in a xx/xx/xx date. The default is month/day/year; any permutation of mdy is legal.} \item{...}{if \code{x} is character, then any other arguments from \code{mdy.date()} can be used as well.} } \value{ For each date, the number of days between it and January 1, 1960. The date will be missing if the string is not interpretable. } \details{ If \code{x} is numeric, then \code{floor(x)} is returned, e.g., \code{as.date(35)} is the same as \code{as.date(35.2)} and gives February 5, 1960 (\samp{5Feb60}). If \code{x} is character, the program attempts to parse it. } \seealso{ \code{\link{mdy.date}}, \code{\link{date.mmddyy}}, \code{\link{date.ddmmmyy}} } \examples{ as.date(c("1jan1960", "2jan1960", "31mar1960", "30jul1960")) } \keyword{chron} date/DESCRIPTION0000644000175100001440000000211114366211520012706 0ustar hornikusersPackage: date Version: 1.2-42 Title: Functions for Handling Dates Authors@R: c(person("Terry", "Therneau", role = "aut", email = "therneau@mayo.edu", comment = "S original"), person("Thomas", "Lumley", role = "trl", comment = "R port"), person("Kjetil", "Halvorsen", role = "trl", comment = "R port"), person("Kurt", "Hornik", role = c("trl", "aut", "cre"), email = "Kurt.Hornik@R-project.org", comment = c(ORCID = "0000-0003-4198-9911", "R port")), person("R Core Team", role = "ctb")) Description: Functions for handling dates. Imports: graphics License: GPL-2 NeedsCompilation: yes Packaged: 2023-01-31 12:41:14 UTC; hornik Author: Terry Therneau [aut] (S original), Thomas Lumley [trl] (R port), Kjetil Halvorsen [trl] (R port), Kurt Hornik [trl, aut, cre] (, R port), R Core Team [ctb] Maintainer: Kurt Hornik Repository: CRAN Date/Publication: 2023-01-31 13:10:40 UTC date/src/0000755000175100001440000000000014350260346011777 5ustar hornikusersdate/src/init.c0000644000175100001440000000061613616575561013125 0ustar hornikusers#include #include #include void char_date(int *n, int *order, char **cdate, int *month, int *day, int *year); static const R_CMethodDef CEntries[] = { {"char_date", (DL_FUNC) &char_date, 6}, {NULL, NULL, 0} }; void R_init_date(DllInfo *dll) { R_registerRoutines(dll, CEntries, NULL, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } date/src/char_date.c0000644000175100001440000000633314350260346014062 0ustar hornikusers/* * Tear down a date string into its component parts */ #include #include char * id(char *str, int array[], int k); void char_date(int *n, int *order, char **cdate, int *month, int *day, int *year) { register int i,k, ii; register char *j; register char *cc; int what[3]; int len; char tdate[11]; for (i=0; i< *n; i++) { cc = cdate[i]; for (j=cc; *j != '\0'; j++) /* upper case to lower case */ if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", *j) !=NULL) *j += 'a' - 'A'; /* ** If it is pure numeric, put in some delimiters based on ** assumptions */ len = strlen(cc); for (k=0; k '9')) break; if (k>=len && (len>=5 && len<=8)) { if (len==5) snprintf(tdate, 11, "0%c/%c%c/%c%c", cc[0], cc[1], cc[2], cc[3], cc[4]); else if (len==6) snprintf(tdate, 11, "%c%c/%c%c/%c%c", cc[0], cc[1], cc[2], cc[3], cc[4], cc[5]); else { if (len==7) { for (ii=7; ii>0; ii--) cc[ii]= cc[ii-1]; cc[0] = '0'; } if (order[0]==1) snprintf(tdate, 11, "%c%c%c%c/%c%c/%c%c", cc[0], cc[1], cc[2], cc[3], cc[4], cc[5], cc[6], cc[7]); else if (order[1]==1) snprintf(tdate, 11, "%c%c/%c%c%c%c/%c%c", cc[0], cc[1], cc[2], cc[3], cc[4], cc[5], cc[6], cc[7]); else snprintf(tdate, 11, "%c%c/%c%c/%c%c%c%c", cc[0], cc[1], cc[2], cc[3], cc[4], cc[5], cc[6], cc[7]); } cc = tdate; } cc = id(cc, what, 0); cc = id(cc, what, 1); cc = id(cc, what, 2); if (*cc != '\0') what[2] =0; if (what[0] <0) { month[i] = -1*what[0]; day[i] = what[1]; year[i] = what[2]; } else if (what[1] <0) { month[i] = -1*what[1]; day[i] = what[0]; year[i] = what[2]; } else for (k=0; k<3; k++) { switch (order[k]) { case 1: year[i] = what[k]; break; case 2: month[i]= what[k]; break; case 3: day[i] = what[k]; break; } } } } char * id(char *str, int array[], int k) { register int i; register char *j; /*skip any delimiters (leading blanks are always ok) */ while (*str==' ') str++; if (k>0) if (strchr(" -/,", *str) !=NULL) str++; while (*str==' ') str++; if (*str=='\0') { array[k]=0; return(str); } if (strchr("0123456789", *str) ==NULL) { if (strstr(str, "jan")==str) array[k] = -1; else if (strstr(str, "feb")==str) array[k] = -2; else if (strstr(str, "mar")==str) array[k] = -3; else if (strstr(str, "apr")==str) array[k] = -4; else if (strstr(str, "may")==str) array[k] = -5; else if (strstr(str, "jun")==str) array[k] = -6; else if (strstr(str, "jul")==str) array[k] = -7; else if (strstr(str, "aug")==str) array[k] = -8; else if (strstr(str, "sep")==str) array[k] = -9; else if (strstr(str, "oct")==str) array[k] = -10; else if (strstr(str, "nov")==str) array[k] = -11; else if (strstr(str, "dec")==str) array[k] = -12; else array[k] =0; /* pass over the rest of the string */ while( *str!= '\0' && strchr("januaryfebmrchpilgstovd", *str)!=NULL) str++; } else { /*is a number */ i =0; while (*str!= '\0' && (j=strchr("0123456789", *str)) !=NULL) { str++; i = (10*i) +(*j - '0'); } array[k] = i; } return(str); } date/R/0000755000175100001440000000000013224134541011405 5ustar hornikusersdate/R/date.R0000644000175100001440000002424313224134541012452 0ustar hornikusersas.date <- function(x, order = "mdy", ...) { if (inherits(x, "date")) x else if (is.character(x)) { order.vec <- switch(order, "ymd" = c(1, 2, 3), "ydm" = c(1, 3, 2), "mdy" = c(2, 3, 1), "myd" = c(2, 1, 3), "dym" = c(3, 1, 2), "dmy" = c(3, 2, 1), stop("Invalid value for 'order' option")) nn <- length(x) temp <- .C(char_date, as.integer(nn), as.integer(order.vec), as.character(x), month = integer(nn), day = integer(nn), year = integer(nn)) month <- ifelse(temp$month < 1 | temp$month > 12, NA, temp$month) day <- ifelse(temp$day == 0, NA, temp$day) year <- ifelse(temp$year == 0, NA, temp$year) temp <- mdy.date(month, day, year, ...) } else if (is.numeric(x)) { temp <- floor(x) attr(temp, "class") <- "date" } else stop("Cannot coerce to date format") temp } is.date <- function(x) inherits(x, "date") Ops.date <- function(e1, e2) { ## Certain operation yield a date, others just give a number. In ## order to make plotting functions work well, we end up allowing ## most all numeric operations. if (missing(e2)) stop("Unary operations not meaningful for dates") if (.Generic == "&" || .Generic== "|") stop(paste("'", .Generic, "' not meaningful for dates", sep = "")) class(e1) <- NULL class(e2) <- NULL if (.Generic == "-") { if (.Method[2] == "" ) { ## subtract a constant from a date e1 <- as.integer(e1 - e2) class(e1) <- "date" e1 } else if ((.Method[1] == "Ops.date" && .Method[2] == "Ops.date") || (.Method[1] == "")) e1 - e2 else ## date - factor should fail stop("Invalid operation for dates") } else if (.Generic == "+") { if (.Method[1] == "" || .Method[2]=="") { ## add constant to a date e1 <- as.integer(e1 + e2); class(e1) <- "date" e1 } else e1 + e2 } else get(.Generic)(e1, e2) } Math.date <- function(...) stop("Invalid operation on dates") Summary.date <- function (..., na.rm = FALSE) { ok <- switch(.Generic, min = , max = , range = TRUE, FALSE) if (!ok) stop(paste(.Generic, "not defined for dates")) as.date(NextMethod(.Generic)) } "[.date" <- function(x, ..., drop = TRUE) { cl <- class(x) class(x) <- NULL x <- NextMethod("[") class(x) <- cl x } "[[.date" <- function(x, ..., drop = TRUE) { cl <- class(x) class(x) <- NULL x <- NextMethod("[[") class(x) <- cl x } as.character.date <- function(x, ...) { fun <- options()$print.date if (is.null(fun)) date.ddmmmyy(x) else get(fun)(x) } as.data.frame.date <- as.data.frame.vector as.vector.date <- function(x, mode = "any") { if (mode == "any") as.vector(as.numeric(x), mode) else if (mode == "character" || mode == "logical" || mode == "list") as.vector(as.character(x), mode) else as.vector(unclass(x), mode) } is.na.date <- function(x) { NextMethod(.Generic) } plot.date <- function(x, y, ..., axes, xaxt, xlab, ylab, xlim = range(x, na.rm = TRUE), ylim = range(y, na.rm = TRUE)) { if(missing(xlab)) xlab <- deparse(substitute(x)) if(missing(ylab)) ylab <- deparse(substitute(y)) class(x) <- NULL # after deparse(substitute()) if(!missing(axes) && !axes) # argument axes works plot(x, y, ..., axes = axes, xlab = xlab, ylab = ylab, xlim = xlim, ylim = ylim) else if(!missing(xaxt)) plot(x, y, ..., xaxt = xaxt, xlab = xlab, ylab = ylab, xlim = xlim, ylim = ylim) else { plot(x, y, ..., xaxt = "n", xlab = xlab, ylab = ylab, xlim = xlim, ylim = ylim) x <- c(x[!is.na(x)], xlim) # draws axis completely when # using xlim xd <- date.mdy(x) ## get default for n from par("lab") temp <- pretty(x, n = par("lab")[1]) delta <- temp[2] - temp[1] if(delta < 1) temp <- seq(min(x), max(x), 1) else if(delta > 182) { temp <- xd$year + (x - mdy.date(1, 1, xd$year))/365 ## get default for n from par("lab") temp <- pretty(temp, n = par("lab")[1]) temp <- mdy.date(1, 1, floor(temp)) + floor((temp %% 1) * 365) } axis(1, temp, as.character.date(temp), ...) } } print.date <- function(x, quote, prefix, ...) { if (missing(quote)) quote <- FALSE invisible(print(as.character(x), quote = quote)) } summary.date <- function(object, ...) { y <- as.character(range(object), ...) names(y) <- c("First ", "Last ") y } Axis.date <- function(x = NULL, at = NULL, xlim=range(x, na.rm=TRUE), ..., side, labels = NULL) { if(!is.null(x)) { x <- c(x[!is.na(x)], xlim) xd <- date.mdy(x) temp <- pretty(x, n = par("lab")[1L]) delta <- temp[2L] - temp[1L] if(delta < 1) temp <- seq(min(x), max(x), 1) else if(delta > 182) { temp <- xd$year + (x - mdy.date(1, 1, xd$year)) / 365 temp <- pretty(temp, n = par("lab")[1L]) temp <- mdy.date(1, 1, floor(temp)) + floor((temp %% 1) * 365) } axis(side = side, at = temp, labels = as.character.date(temp), ...) } else { axis(side = side, at = at, labels = labels, ...) } } mdy.date <- function(month, day, year, nineteen = TRUE, fillday = FALSE, fillmonth = FALSE) { ## Get the Julian date, but centered a la SAS, i.e., Jan 1 1960 is ## day 0. Algorithm taken from Numerical Recipies. temp <- any((month != trunc(month)) | (day != trunc(day)) | (year != trunc(year))) if (!is.na(temp) && temp) { warning("Non integer input values were truncated in mdy.date") month <- trunc(month) day <- trunc(day) year <- trunc(year) } if (nineteen) year <- ifelse(year < 100, year + 1900, year) ## Force input vectors to be the same length, but in a way that ## gives an error if their lengths aren't multiples of each other. temp <- numeric(length(month + day + year)) month <- month + temp day <- day + temp year <- year + temp if (fillmonth) { temp <- is.na(month) month[temp] <- 7 day[temp] <- 1 } if (fillday) day[is.na(day)] <- 15 month[month < 1 | month > 12] <- NA day[day < 1] <- NA year[year == 0] <- NA # there is no year 0 year <- ifelse(year < 0, year + 1, year) tyear<- ifelse(month > 2, year, year - 1) tmon <- ifelse(month > 2, month + 1, month + 13) julian <- trunc(365.25 * tyear) + trunc(30.6001 * tmon) + day - 715940 ## Check for Gregorian calendar changeover on Oct 15, 1582 temp <- trunc(0.01 * tyear) save <- ifelse(julian >= -137774, julian + 2 + trunc(.25 * temp) - temp, julian) ## Check for invalid days (31 Feb, etc.) by calculating the Julian ## date of the first of the next month year <- ifelse(month == 12, year+1, year) month<- ifelse(month == 12, 1, month + 1) day <- 1 tyear<- ifelse(month > 2, year, year - 1) tmon <- ifelse(month > 2, month + 1, month + 13) julian <- trunc(365.25 * tyear) + trunc(30.6001 * tmon) + day - 715940 temp <- trunc(0.01 * tyear) save2<- ifelse(julian >= -137774, julian + 2 + trunc(.25 * temp) - temp, julian) temp <- as.integer(ifelse(save2 > save, save, NA)) attr(temp, "class") <- "date" temp } date.mdy <- function(sdate, weekday = FALSE) { ## Return the month, day, and year given a julian date attr(sdate, "class") <- NULL # Stop any propogation of methods sdate <- floor(sdate + 2436935) # From SAS to Num Recipies base # point wday <- as.integer((sdate + 1) %% 7 +1) temp <- ((sdate - 1867216) -.25) / 36524.25 sdate <- ifelse(sdate >= 2299161, trunc(sdate+ 1 +temp - trunc(.25 * temp)), sdate) jb <- sdate + 1524 jc <- trunc(6680 + ((jb - 2439870) - 122.1) / 365.25) jd <- trunc(365.25 * jc) je <- trunc((jb - jd)/ 30.6001) day <- (jb - jd) - trunc(30.6001 * je) month <- as.integer(ifelse(je > 13, je - 13, je - 1)) year <- as.integer(ifelse(month > 2, jc - 4716, jc - 4715)) year <- as.integer(ifelse(year <= 0, year - 1, year)) if (weekday) list(month = month, day = day, year = year, weekday = wday) else list(month = month, day = day, year = year) } date.ddmmmyy <- function(sdate) { temp <- date.mdy(sdate) tyr <- ifelse(floor(temp$year/100) == 19, temp$year-1900, temp$year) month <- month.abb[temp$month] ifelse(is.na(sdate), as.character(NA), paste(temp$day, month, tyr, sep = "")) } date.mmddyy <- function(sdate, sep = "/") { temp <- date.mdy(sdate) tyr <- ifelse(floor(temp$year / 100) == 19, temp$year - 1900, temp$year) ifelse(is.na(sdate), as.character(NA), paste(temp$month, temp$day, tyr, sep = sep)) } date.mmddyyyy <- function(sdate, sep = "/") { temp <- date.mdy(sdate) ifelse(is.na(sdate), as.character(NA), paste(temp$month, temp$day, temp$year, sep = sep)) } as.Date.date <- function(x, ...) { if(inherits(x, "date")) { x <- (x - 3653) # origin 1960-01-01 return(structure(x, class = "Date")) } else stop(gettextf("'%s' is not a \"date\" object", deparse(substitute(x)) )) } as.POSIXct.date <- function(x, ...) { if(inherits(x, "date")) { x <- (x - 3653) * 86400 # origin 1960-01-01 return(structure(x, class = c("POSIXct", "POSIXt"))) } else stop(gettextf("'%s' is not a \"date\" object", deparse(substitute(x)) )) } as.POSIXlt.date <- function(x, ...) as.POSIXlt(as.POSIXct(x), ...) date/MD50000644000175100001440000000117414366211520011520 0ustar hornikusers92c7f75ffebd48114045bc3de613c5ac *ChangeLog 0420815b5e19e662afdd27ef1cb58885 *DESCRIPTION a8b6c18212eecaea56e37d69d9345112 *NAMESPACE f57d803d7b43b4dd5128b1ab3526dc4c *R/date.R 527f9134efafcb21a9f296e6d49a91b7 *man/as.date.Rd 0dbec559eb5a374a7daa6f9724d79350 *man/date.ddmmmyy.Rd 6da259c0f5f184f490ba2ae8c9d10617 *man/date.mdy.Rd 88348f607e88c637d80a07d6a26c9f04 *man/date.mmddyy.Rd 142d36a74c2ff94965e87825db4a192d *man/date.mmddyyyy.Rd 985bc0737a3318f257e33097aaa1be2c *man/date.object.Rd c0b2d7348776c34480f8880afcd768d3 *man/mdy.date.Rd 8590f16484b007fcdb4a9fd5a9b9e58b *src/char_date.c 3dbc83a0b110757f51d1306003a4aed7 *src/init.c