-
Notifications
You must be signed in to change notification settings - Fork 207
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
ymd(column, truncated = 1) parses date incorrectly on Windows #843
Comments
I am also on windows but it is working fine date <- c("18/08", "17/11", "18/08", "18/05", "18/05", "18/07")
data.frame(
date = date,
date = lubridate::ymd(date, truncated = 1)
)
#> date date.1
#> 1 18/08 2018-08-01
#> 2 17/11 2017-11-01
#> 3 18/08 2018-08-01
#> 4 18/05 2018-05-01
#> 5 18/05 2018-05-01
#> 6 18/07 2018-07-01 Created on 2019-12-13 by the reprex package (v0.3.0) Session infodevtools::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 3.6.1 (2019-07-05)
#> os Windows 10 x64
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate French_France.1252
#> ctype French_France.1252
#> tz Europe/Paris
#> date 2019-12-13
#>
#> - Packages -------------------------------------------------------------------
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
#> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1)
#> callr 3.3.2 2019-09-22 [1] CRAN (R 3.6.1)
#> cli 2.0.0 2019-12-09 [1] CRAN (R 3.6.1)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)
#> debugme 1.1.0 2017-10-22 [1] standard (@1.1.0)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.1)
#> devtools 2.2.1 2019-09-24 [1] CRAN (R 3.6.1)
#> digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.1)
#> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1)
#> fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.0)
#> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.1)
#> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0)
#> highr 0.8 2019-03-20 [1] CRAN (R 3.6.1)
#> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1)
#> knitr 1.26 2019-11-12 [1] CRAN (R 3.6.1)
#> lubridate 1.7.4 2018-04-11 [1] CRAN (R 3.6.1)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.1)
#> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.1)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.1)
#> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0)
#> processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.1)
#> ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1)
#> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1)
#> remotes 2.1.0 2019-06-24 [1] CRAN (R 3.6.0)
#> rlang 0.4.2 2019-11-23 [1] CRAN (R 3.6.1)
#> rmarkdown 1.18 2019-11-27 [1] CRAN (R 3.6.1)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.1)
#> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
#> testthat 2.3.1 2019-12-01 [1] CRAN (R 3.6.1)
#> usethis 1.5.1.9000 2019-10-04 [1] Github (r-lib/usethis@3015465)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)
#> xfun 0.11 2019-11-12 [1] CRAN (R 3.6.1)
#> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.6.0)
#>
#> [1] C:/Users/chris/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-3.6.1/library However, I think this is a local issue, if I change it I can reproduce Sys.setlocale("LC_TIME", "Japanese_Japan.932")
#> [1] "Japanese_Japan.932"
date <- c("18/08", "17/11", "18/08", "18/05", "18/05", "18/07")
data.frame(
date = date,
date = lubridate::ymd(date, truncated = 1)
)
#> date date.1
#> 1 18/08 2018-08-01
#> 2 17/11 2017-01-01
#> 3 18/08 2018-08-01
#> 4 18/05 2018-05-01
#> 5 18/05 2018-05-01
#> 6 18/07 2018-07-01 Here is a minimal reprex: lubridate::ymd("17/11", truncated = 1, locale = "Japanese_Japan.932")
#> [1] "2017-01-01"
lubridate::ymd("17/11", truncated = 1, locale = "French_France.1252")
#> [1] "2017-11-01"
lubridate::ymd("17/11", truncated = 1, locale = "English_United States.1252")
#> [1] "2017-11-01" |
@cderv could you please post the value of I don't see this problem with japanese locale on Linux. |
Here is the result > lubridate:::.get_locale_regs("Japanese_Japan.932")
$alpha_flex
b
"((?<b_b>1|2|3|4|5|6|7|8|9|10|11|12)|(?<B_b>1\\?|2\\?|3\\?|4\\?|5\\?|6\\?|7\\?|8\\?|9\\?|10\\?|11\\?|12\\?))(?![[:alpha:]])"
B
"(?<B_B>1\\?|2\\?|3\\?|4\\?|5\\?|6\\?|7\\?|8\\?|9\\?|10\\?|11\\?|12\\?)(?![[:alpha:]])"
a
"((?<a_a>\\?)|(?<A_a>\\?\\?\\?))(?![[:alpha:]])"
A
"(?<A_A>\\?\\?\\?)(?![[:alpha:]])"
Ou
"(?<Ou_Ou>Z)(?![[:alpha:]])"
p
"(?<p>\\?\\?)(?![[:alpha:]])"
$num_flex
d
"(?<d>[012]?[1-9]|3[01]|[12]0)(?!\\d)"
q
"(?<q>[0]?[1-4])(?!\\d)"
H
"(?<H>2[0-4]|[01]?\\d)(?!\\d)"
h
"(?<H>2[0-4]|[01]?\\d)(?!\\d)"
I
"(?<I>1[0-2]|0?[1-9])(?!\\d)"
j
"(?<j>[0-3]?\\d?\\d)(?!\\d)"
M
"(?<M>[0-5]?\\d)(?!\\d)"
S
"((?<OS_S>[0-5]?\\d\\.\\d+)|(?<S>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\\\)(?![[:alpha:]]))|((?<H_s_e>2[0-4]|[01]\\d)\\D*(?<M_s_e>[0-5]\\d)\\D*((?<OS_s_S_e>[0-5]\\d\\.\\d*)|(?<S_s_e>[0-6]\\d))))"
R
"(((?<I_s_e>1[0-2]|0[1-9])\\D*(?<M_s_T_e>[0-5]\\d)\\D*(?<p_s_e>\\\\)(?![[:alpha:]]))|((?<H_s_e>2[0-4]|[01]\\d)\\D*(?<M_s_e>[0-5]\\d)))"
r
"(((?<I_s_e>1[0-2]|0[1-9])\\D*(?<p_s_e>\\\\)(?![[:alpha:]]))|(?<H_s_e>2[0-4]|[01]\\d))"
m
"((?<m_e>1[0-2]|0[1-9])|(((?<b_m_e>1|2|3|4|5|6|7|8|9|10|11|12)|(?<B_m_e>1\\?|2\\?|3\\?|4\\?|5\\?|6\\?|7\\?|8\\?|9\\?|10\\?|11\\?|12\\?))(?![[:alpha:]])))"
OS
"(?<OS_e>[0-5]\\d\\.\\d+)"
z
"((?<Ou_Ou_e>Z)(?![[:alpha:]])|(?<Oz_Oz_e>[-*]\\d{4})|(?<OO_e>[-*]\\d{2}:\\d{2})|(?<Oo_e>[-*]\\d{2}))"
$wday_names
$wday_names$abr
[1] "\\?"
$wday_names$full
[1] "\\?\\?\\?"
$month_names
$month_names$abr
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12"
$month_names$full
[1] "1\\?" "2\\?" "3\\?" "4\\?" "5\\?" "6\\?" "7\\?" "8\\?" "9\\?" "10\\?"
[11] "11\\?" "12\\?" |
Apologies for the belated update. Here is my result for lubridate:::.get_locale_regs("Japanese_Japan.932")
#> $alpha_flex
#> b
#> "((?<b_b>1|2|3|4|5|6|7|8|9|10|11|12)|(?<B_b>1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月))(?![[:alpha:]])"
#> B
#> "(?<B_B>1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月)(?![[:alpha:]])"
#> a
#> "((?<a_a>木|月|火|日|金|水|土)|(?<A_a>木曜日|月曜日|火曜日|日曜日|金曜日|水曜日|土曜日))(?![[:alpha:]])"
#> A
#> "(?<A_A>木曜日|月曜日|火曜日|日曜日|金曜日|水曜日|土曜日)(?![[:alpha:]])"
#> Ou
#> "(?<Ou_Ou>Z)(?![[:alpha:]])"
#> p
#> "(?<p>午前|午後)(?![[:alpha:]])"
#>
#> $num_flex
#> d
#> "(?<d>[012]?[1-9]|3[01]|[12]0)(?!\\d)"
#> q
#> "(?<q>[0]?[1-4])(?!\\d)"
#> H
#> "(?<H>2[0-4]|[01]?\\d)(?!\\d)"
#> h
#> "(?<H>2[0-4]|[01]?\\d)(?!\\d)"
#> I
#> "(?<I>1[0-2]|0?[1-9])(?!\\d)"
#> j
#> "(?<j>[0-3]?\\d?\\d)(?!\\d)"
#> M
#> "(?<M>[0-5]?\\d)(?!\\d)"
#> S
#> "((?<OS_S>[0-5]?\\d\\.\\d+)|(?<S>[0-6]?\\d))(?!\\d)"
#> s
#> "((?<OS_S>[0-5]?\\d\\.\\d+)|(?<S>[0-6]?\\d))(?!\\d)"
#> U
#> "(?<U>[0-5]?\\d)(?!\\d)"
#> w
#> "(?<w>[0-6])(?!\\d)"
#> u
#> "(?<u>[1-7])(?!\\d)"
#> W
#> "(?<W>[0-5]?\\d)(?!\\d)"
#> Y
#> "(?<Y>\\d{4})(?!\\d)"
#> y
#> "((?<Y_y>\\d{4})|(?<y>\\d{2}))(?!\\d)"
#> Oz
#> "(?<Oz_Oz>[-+]\\d{4})(?!\\d)"
#> OO
#> "(?<OO>[-+]\\d{2}:\\d{2})(?!\\d)"
#> Oo
#> "(?<Oo>[-+]\\d{2})(?!\\d)"
#> T
#> "(((?<I_s>1[0-2]|0?[1-9])\\D+(?<M_s_T>[0-5]?\\d)\\D+((?<OS_s_T_S>[0-5]?\\d\\.\\d+)|(?<S_s_T>[0-6]?\\d))\\D*(?<p_s>午前|午後)(?![[:alpha:]]))|((?<H_s>2[0-4]|[01]?\\d)\\D+(?<M_s>[0-5]?\\d)\\D+((?<OS_s_S>[0-5]?\\d\\.\\d+)|(?<S_s>[0-6]?\\d))))(?!\\d)"
#> R
#> "(((?<I_s>1[0-2]|0?[1-9])\\D+(?<M_s_T>[0-5]?\\d)\\D*(?<p_s>午前|午後)(?![[:alpha:]]))|((?<H_s>2[0-4]|[01]?\\d)\\D+(?<M_s>[0-5]?\\d)))(?!\\d)"
#> r
#> "(((?<I_s>1[0-2]|0?[1-9])\\D*(?<p_s>午前|午後)(?![[:alpha:]]))|(?<H_s>2[0-4]|[01]?\\d))(?!\\d)"
#> m
#> "((?<m>1[0-2]|0?[1-9](?!\\d))|(((?<b_m>1|2|3|4|5|6|7|8|9|10|11|12)|(?<B_m>1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月))(?![[:alpha:]])))"
#> OS
#> "(?<OS_f>[0-5]\\d\\.\\d+)"
#> z
#> "((?<Ou_Ou>Z)(?![[:alpha:]])|(?<Oz_Oz>[-+]\\d{4})(?!\\d)|(?<OO>[-+]\\d{2}:\\d{2})(?!\\d)|(?<Oo>[-+]\\d{2})(?!\\d))"
#>
#> $alpha_exact
#> b
#> "((?<b_b_e>1|2|3|4|5|6|7|8|9|10|11|12)|(?<B_b_e>1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月))(?![[:alpha:]])"
#> B
#> "(?<B_B_e>1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月)(?![[:alpha:]])"
#> a
#> "((?<a_a_e>木|月|火|日|金|水|土)|(?<A_a_e>木曜日|月曜日|火曜日|日曜日|金曜日|水曜日|土曜日))(?![[:alpha:]])"
#> A
#> "(?<A_A_e>木曜日|月曜日|火曜日|日曜日|金曜日|水曜日|土曜日)(?![[:alpha:]])"
#> Ou
#> "(?<Ou_Ou_e>Z)(?![[:alpha:]])"
#> p
#> "(?<p_e>午前|午後)(?![[:alpha:]])"
#>
#> $num_exact
#> d
#> "(?<d_e>[012][1-9]|3[01]|[12]0)"
#> q
#> "(?<q_e>[0][1-4])"
#> H
#> "(?<H_e>2[0-4]|[01]\\d)"
#> h
#> "(?<H_e>2[0-4]|[01]\\d)"
#> I
#> "(?<I_e>1[0-2]|0[1-9])"
#> j
#> "(?<j_e>[0-3]\\d\\d)"
#> M
#> "(?<M_e>[0-5]\\d)"
#> S
#> "((?<OS_S_e>[0-5]\\d\\.\\d*)|(?<S_e>[0-6]\\d))"
#> s
#> "((?<OS_S_e>[0-5]\\d\\.\\d*)|(?<S_e>[0-6]\\d))"
#> U
#> "(?<U_e>[0-5]\\d)"
#> w
#> "(?<w_e>[0-6])"
#> u
#> "(?<u_e>[1-7])"
#> W
#> "(?<W_e>[0-5]\\d)"
#> Y
#> "(?<Y_e>\\d{4})"
#> y
#> "((?<Y_y_e>\\d{4})|(?<y_e>\\d{2}))"
#> Oz
#> "(?<Oz_Oz_e>[-*]\\d{4})"
#> OO
#> "(?<OO_e>[-*]\\d{2}:\\d{2})"
#> Oo
#> "(?<Oo_e>[-*]\\d{2})"
#> T
#> "(((?<I_s_e>1[0-2]|0[1-9])\\D*(?<M_s_T_e>[0-5]\\d)\\D*((?<OS_s_T_S_e>[0-5]\\d\\.\\d*)|(?<S_s_T_e>[0-6]\\d))\\D*(?<p_s_e>午前|午後)(?![[:alpha:]]))|((?<H_s_e>2[0-4]|[01]\\d)\\D*(?<M_s_e>[0-5]\\d)\\D*((?<OS_s_S_e>[0-5]\\d\\.\\d*)|(?<S_s_e>[0-6]\\d))))"
#> R
#> "(((?<I_s_e>1[0-2]|0[1-9])\\D*(?<M_s_T_e>[0-5]\\d)\\D*(?<p_s_e>午前|午後)(?![[:alpha:]]))|((?<H_s_e>2[0-4]|[01]\\d)\\D*(?<M_s_e>[0-5]\\d)))"
#> r
#> "(((?<I_s_e>1[0-2]|0[1-9])\\D*(?<p_s_e>午前|午後)(?![[:alpha:]]))|(?<H_s_e>2[0-4]|[01]\\d))"
#> m
#> "((?<m_e>1[0-2]|0[1-9])|(((?<b_m_e>1|2|3|4|5|6|7|8|9|10|11|12)|(?<B_m_e>1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月))(?![[:alpha:]])))"
#> OS
#> "(?<OS_e>[0-5]\\d\\.\\d+)"
#> z
#> "((?<Ou_Ou_e>Z)(?![[:alpha:]])|(?<Oz_Oz_e>[-*]\\d{4})|(?<OO_e>[-*]\\d{2}:\\d{2})|(?<Oo_e>[-*]\\d{2}))"
#>
#> $wday_names
#> $wday_names$abr
#> [1] "日" "月" "火" "水" "木" "金" "土"
#>
#> $wday_names$full
#> [1] "日曜日" "月曜日" "火曜日" "水曜日" "木曜日" "金曜日" "土曜日"
#>
#>
#> $month_names
#> $month_names$abr
#> [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12"
#>
#> $month_names$full
#> [1] "1月" "2月" "3月" "4月" "5月" "6月" "7月" "8月" "9月" "10月"
#> [11] "11月" "12月" Created on 2019-12-27 by the reprex package (v0.3.0) |
It's a bug in > x <- c("18/08", "17/11", "18/08", "18/05", "18/05", "18/07")
> strptime(x, "%y/%b%d")
[1] NA "2017-01-01 PST" NA NA NA NA I am afraid I cannot do much about this ATM. The only solution is to drop dependency on strptime in our parser, thing which is planned but is unlikely to happen before summer I am afraid. |
A workaround is to avoid training during the parsing: > parse_date_time(x, c("ym","ymd"), train=F)
[1] "2018-08-01 UTC" "2017-11-01 UTC" "2018-08-01 UTC" "2018-05-01 UTC" "2018-05-01 UTC" "2018-07-01 UTC" |
In below example, I expect 17/11 to be parsed as "2017-11-01" but it's parsed as "2017-01-01"
Created on 2019-12-12 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: