Skip to content
New issue

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

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

Already on GitHub? # to your account

Incorrect parsing of Mon-Year (bY) format #559

Closed
IdoBar opened this issue Jun 28, 2017 · 3 comments
Closed

Incorrect parsing of Mon-Year (bY) format #559

IdoBar opened this issue Jun 28, 2017 · 3 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@IdoBar
Copy link

IdoBar commented Jun 28, 2017

Hi,

I'm trying to parse a very simple date format, which appears as either %d-%b-%Y, %b-%Y or %Y.
parse_date_time() works great for the 1st and 3rd formats, but is unable to parse the second one (though guess_date() successfully guesses the right format).
Examples:

> parse_date_time("May-2010", orders="bY")
[1] NA
Warning message:
All formats failed to parse. No formats found. 
> guess_formats("May-2010", orders="bY")
     bY 
"%b-%Y" 
> parse_date_time("May-2010", orders="%b-%Y")
[1] NA
Warning message:
All formats failed to parse. No formats found. 
> parse_date_time("May-2010", orders="Y")
[1] "2010-01-01 UTC"
> parse_date_time("01-May-2010", orders="dbY")
[1] "2010-05-01 UTC"

I'm using R 3.3.1, with lubridate 1.6.0, on a Windows machine with "English_Australia.1252" locale.

@cderv
Copy link
Contributor

cderv commented Jun 28, 2017

Base function strptime does not parse correctly.

library(lubridate)
#> 
#> Attachement du package : 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date
old <- Sys.getlocale("LC_TIME")
Sys.setlocale("LC_TIME", "eng")
#> [1] "English_United Kingdom.1252"
strptime("May-2010", format="%b-%Y")
#> [1] NA
strptime("10-May-2010", format="%d-%b-%Y")
#> [1] "2010-05-10 CEST"

If we use orders = "Omy" instead of orders="by", it works (using lubridate C-parser)

parse_date_time("May-2010", orders="OmY")
#> [1] "2010-05-01 UTC"

@vspinu
Copy link
Member

vspinu commented Jun 28, 2017

This should be working. Our C parser handles English months but for some reasons "bY" is not getting through.

> parse_date_time2("May-2010", orders="bY")
[1] "2010-05-01 UTC"
> parse_date_time(c("01-May-2010", "May-2010", "2010"), orders=c("dbY", "bY", "Y"))
[1] "2010-05-01 UTC" "2010-01-01 UTC" "2010-01-01 UTC"

@vspinu vspinu added the bug an unexpected problem or unintended behavior label Jun 28, 2017
@IdoBar
Copy link
Author

IdoBar commented Jun 29, 2017

Thanks Christophe,

Using Om instead of b worked for me and parsed correctly all the appearances, using orders=c("dOmY", "OmY", "Y"), so I'll go with that for now.
Vitalie, using parse_date_time2("May-2010", orders="bY") worked alright, but only when I know in advance the format to expect and it is not flexible to "guess" when the input of mixed formats.

Thanks for your responses, Ido

@vspinu vspinu closed this as completed in 72c87df Oct 2, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants