Skip to content

Commit

Permalink
added deprecation for internal function parse_date
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed Jul 30, 2012
1 parent ddd4680 commit 2a2b4a2
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 1 deletion.
85 changes: 84 additions & 1 deletion INSPIRATIONS
Expand Up @@ -26,4 +26,87 @@ Date time standards

# Ordered from least precise to most
# 2003-08-06 04:28-02:00
# 2003-08-06T04:28Z
# 2003-08-06T04:28Z


Variety of formats (from http://chronic.rubyforge.org/):

Simple

thursday
november
summer
friday 13:00
mon 2:35
4pm
6 in the morning
friday 1pm
sat 7 in the evening
yesterday
today
tomorrow
this tuesday
next month
last winter
this morning
last night
this second
yesterday at 4:00
last friday at 20:00
last week tuesday
tomorrow at 6:45pm
afternoon yesterday
thursday last week

Complex

3 years ago
5 months before now
7 hours ago
7 days from now
1 week hence
in 3 hours
1 year ago tomorrow
3 months ago saturday at 5:00 pm
7 hours before tomorrow at noon
3rd wednesday in november
3rd month next year
3rd thursday this september
4th day last week

Specific Dates

January 5
dec 25
may 27th
October 2006
oct 06
jan 3 2010
february 14, 2004
3 jan 2000
17 april 85
5/27/1979
27/5/1979
05/06
1979-05-27
Friday
5
4:00
17:00
0800

Specific Times (many of the above with an added time)

January 5 at 7pm
1979-05-27 05:00
etc


Natural (from http://code.google.com/p/datejs/)

Date.parse('July 23rd 2004') // Fri Jul 23 2004
Date.parse('Sat July 3, 2004') // Sat Jul 03 2004

Date.parse('July 8th, 2004, 10:30 PM') // Thu Jul 08 2004 22:30:00
Date.parse('2004-07-15T06:45:00') // Thu Jul 15 2004 06:45:00
Date.parse('Thu, 1 July 2004 22:30:00 GMT') // Thu Jul 01 2004 16:30:00
17 changes: 17 additions & 0 deletions R/parse.r
Expand Up @@ -633,4 +633,21 @@ parseDateTime <- function(x, formats, tz = "UTC", sep_regexp = "[^[:alnum:]]+",
}


##' Deprecated internal function, use \code{\link{parseDateTime}} instead.
##'
##'
##' @export parse_date
##' @param x -
##' @param formats -
##' @param quiet -
##' @param seps -
##' @param tz -
parse_date <- function(x, formats, quiet = FALSE, seps = find_separator(x), tz = "UTC") {

stop("Internal function parse_date has been removed from lubridate package. Plese use parseDateTime instead.")
}



## parse.r ends here

80 changes: 80 additions & 0 deletions inst/tests/test-parsers.R
Expand Up @@ -289,7 +289,87 @@ test_that("hms functions correctly throw errors", {



## x <- c("09-01-01 12:23", "09-01-02", "09-01-03")


## x <- c("02/11/92 23", "31/03/92 22", "01/10/92 01:03",
## "02/02/92 18:21:03", "02/01/92 16:56:26")


## parse_time(x, c("%d%m%y%H%M%S", "%d%m%y"))

## parse_time(x, c("%d%m%y%H%M%S"))
## parse_time(x, c("%d%m%y%H%M%S"), missing = 2)

## x <- c("11/92", "92", "02/02/92", "02/01/92")
## parse_time(x, "%d%m%y", missing = -2)

## x <- c("07-03-02", "92", "02/02/92", "02/01/92")
## ## gives junk
## parse_time(x, "%d%m%y", missing = -2)
## ## only reliable way is to specify formats explicitly:
## parse_time(x, c("%d/%m/%y", "%y-%m-%d", "%y"), sep = NULL)

## x <- c("02/11/92 23", "31/03/92 22", "01/10/92 01:03",
## "02/02/92 18:21:03", "02/01/92 16:56:26")

## dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")

## mdy(dates)

## options(digits.secs = 3)
## tt <- rep(as.character(Sys.time()), 10^6)
## system.time(out <- as.POSIXct(tt))
## system.time(out <- ymd_hms(tt))
## system.time(out <- ymd_hms(tt, frac = T))

## options(digits.secs = 0)
## tt <- rep(as.character(Sys.time()), 10^3)
## system.time(out <- ymd_hms(tt))
## str(out)

## system.time(ms <- as.numeric(gsub(".*\\.([^.]*)", "\\1", tt)))
## system.time(ms <- as.numeric(gsub("(.*)(\\.([^.]))?", "\\3", tt)))
## (gsub(".*\\.([^.]*)$", "", "2012-07-20 14:13:46"))

## system.time(parse_time(tt, "%Y%m%d", sep = "-"))
## system.time(parse_time(tt, list(c("%Y", "%m", "%d")), sep = "-"))

## system.time(parse_date(tt, list(c("%Y", "%m", "%d")), seps = "-"))

## tt <- rep("3.4.5", 10^6)

## system.time(out <- strsplitt(t, "[[:alnum:]]"))

## x <- c("1jan1960135412", "2jan1960", "31mar1960", "30jul1960")
## str(unclass(z <- strptime(x, "%d%b%Y%k%M%S")))

## x <- c("09:10:01", "09:10:02", "09:10:03")
## hms(x)

## x <- rep(c("1970-01-01 09:10:01"), 10^6)
## system.time(str(strptime(x, "%Y-%m-%d %H:%M:%S")))
## system.time(lubridate:::hms(x))

## x <- rep("7 6", 10^5)
## ms(x)


## y <- c("2011-12-31 12:9:23.3", "2011-12-31 2:9", "10-03-04 12:00", "10-03-04 12", "10-03-04 1204")
## strptime(y, format = "%y-%m-%d %H:%M") ## [1] NA "2010-03-04 12:00:00"
## strptime(y, format = "%Y-%m-%d %H:%M") ## [1] "2011-12-31 12:59:00" "10-03-04 12:00:00"
## strptime(y, format = "%Y-%m-%d %H:%M") ## [1] "2011-12-31 12:59:00" "10-03-04 12:00:00"
## unclass(strptime(y, format = "%Y-%m-%d %H:%M:%OS")) ## [1] "2011-12-31 12:59:00" "10-03-04 12:00:00"

## ymd_hm(y) ## [1] "2011-12-31 12:59:00 UTC" "2010-03-04 12:00:00 UTC"
## (ymd_hm(y, missing = 1))


## ymd_hms("2011-12-31 11:09:23PM")
## lubridate::ymd_hms("2011-12-31 11:09:23PM")


## ymd_hms("2011-12-31 11:9:23 PM")
## lubridate::ymd_hms("2011-12-31 11:9:23 PM")


0 comments on commit 2a2b4a2

Please sign in to comment.