Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for day of week in parse_datetime #763

Merged
merged 1 commit into from Jun 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -32,6 +32,7 @@ you would pass `skip = 3`, now you only need to pass `skip = 2`.
* `read_*()` files now support reading from the clipboard by using `clipboard()` (#656).
* `write_file()` gains a `sep` argument, to specify the line separator (#665).
* Allow files to be read via FTP over SSH by recognising `sftp` as a URL protocol (#707, @jdeboer).
* `parse_date*() accepts `%a` for local day of week (#763, @tigertoes).

## Bug Fixes

Expand Down
3 changes: 2 additions & 1 deletion R/collectors.R
Expand Up @@ -257,7 +257,8 @@ col_factor <- function(levels, ordered = FALSE, include_na = FALSE) {
#' 70-99 -> 1970-1999.
#' \item Month: "\%m" (2 digits), "\%b" (abbreviated name in current
#' locale), "\%B" (full name in current locale).
#' \item Day: "\%d" (2 digits), "\%e" (optional leading space)
#' \item Day: "\%d" (2 digits), "\%e" (optional leading space),
#' "%a" (abbreviated name in current locale).
#' \item Hour: "\%H" or "\%I", use I (and not H) with AM/PM.
#' \item Minutes: "\%M"
#' \item Seconds: "\%S" (integer seconds), "\%OS" (partial seconds)
Expand Down
3 changes: 2 additions & 1 deletion man/parse_datetime.Rd

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

4 changes: 4 additions & 0 deletions src/DateTimeParser.h
Expand Up @@ -173,6 +173,10 @@ class DateTimeParser {
if (!consumeInteger1(2, &day_, false))
return false;
break;
case 'a': // abbreviated day of week
if (!consumeString(pLocale_->dayAb_, &day_))
return false;
break;
case 'e': // day with optional leading space
if (!consumeInteger1WithSpace(2, &day_))
return false;
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-parsing-datetime.R
Expand Up @@ -167,6 +167,16 @@ test_that("locale affects months", {
expect_equal(parse_date("1 janvier 2010", "%d %B %Y", locale = fr), jan1)
})

test_that("locale affects day of week", {
a <- parse_datetime("2010-01-01")
b <- parse_date("2010-01-01")
fr <- locale("fr")
expect_equal(parse_datetime("Ven. 1 janv. 2010", "%a %d %b %Y", locale=fr), a)
expect_equal(parse_date("Ven. 1 janv. 2010", "%a %d %b %Y", locale=fr), b)
expect_warning(parse_datetime("Fri 1 janv. 1020", "%a %d %b %Y", locale=fr))
expect_warning(parse_date("Fri 1 janv. 2010", "%a %d %b %Y", locale=fr))
})

test_that("locale affects am/pm", {
a <- parse_time("1:30 PM", "%H:%M %p")
b <- parse_time("오후 1시 30분", "%p %H시 %M분", locale = locale("ko"))
Expand Down