Skip to content

Commit

Permalink
[Fix #442] Implement yq parser
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed Aug 3, 2016
1 parent 2ab1838 commit 2cd8874
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export(ymd)
export(ymd_h)
export(ymd_hm)
export(ymd_hms)
export(yq)
exportClasses(Duration)
exportClasses(Interval)
exportClasses(Period)
Expand Down
6 changes: 4 additions & 2 deletions R/parse.r
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ dmy <- function(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME")
dym <- function(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"), truncated = 0)
.parse_xxx(..., orders = "dym", quiet = quiet, tz = tz, locale = locale, truncated = truncated)

#' @export
#' @rdname ymd
yq <- function(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"))
.parse_xxx(..., orders = "yq", quiet = quiet, tz = tz, locale = locale, truncated = 0)

##' Parse dates that have hours, minutes, or seconds elements.
##'
Expand Down Expand Up @@ -809,8 +813,6 @@ fast_strptime <- function(x, format, tz = "UTC", lt = TRUE){
}

.parse_xxx <- function(..., orders, quiet, tz = NULL, locale = locale, truncated){
## if(!missing(tz))
## .deprecated_arg("tz", "1.5.6", 2)
dates <- unlist(lapply(list(...), .num_to_date), use.names = FALSE)
if(is.null(tz)){
as.Date.POSIXct(parse_date_time(dates, orders, quiet = quiet, tz = "UTC",
Expand Down
16 changes: 12 additions & 4 deletions man/parse_date_time.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/ymd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/testthat/test-parsers.R
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ test_that("Quarters are parsed correctly", {
out <- ymd(c("2016-01-01 UTC", "2016-04-01 UTC", "2016-07-01 UTC", "2016-10-01 UTC", NA), tz = "UTC")
expect_equal(parse_date_time2(qs, orders = "Yq"), out)
expect_equal(parse_date_time(qs, orders = "Yq"), out)
expect_equal(yq(qs, tz = "UTC"), out)
expect_equal(yq("16.1", "17.3", "2016.1"), ymd(c("2016-01-01", "2017-07-01", "2016-01-01")))
})

test_that( "Vectors of NA's are parsed as vectors of NA's", {
Expand Down

2 comments on commit 2cd8874

@hadley
Copy link
Member

@hadley hadley commented on 2cd8874 Aug 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you closed the wrong issue

@hadley
Copy link
Member

@hadley hadley commented on 2cd8874 Aug 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you already re-opened - github notifications seem really flakey this morning.

Please sign in to comment.