Allow format strings to be added #3

Closed
eddelbuettel opened this Issue Sep 13, 2016 · 5 comments

Projects

None yet

2 participants

@eddelbuettel
Owner
eddelbuettel commented Sep 13, 2016 edited

Would allow to overcome the currently fixed set for odd formats like

  • %y for two-digit year, or even
  • %I %p for 12 hour time and am/pm,
  • any other format we don't currently have.
@adisarid
adisarid commented Sep 14, 2016 edited

Great initiative for doing this package. Important feature in format strings context: some languages/localization (e.g., Hebrew) specify date in %d/%m/%Y instead of the worldwide standard (%m/%d/%Y). When inputting a vector such as:
anytime(c("14/09/2016", "01/09/2016"))
You get an NA for the first value and an opposite day-month for the second value, though you can probably deduce the meaning from some values (in the example the first value) and apply it on "localization-ambiguous" values (in the example, the second).
Probably a unique situation (according to localization), so should be applied using a parameter.

@eddelbuettel
Owner
eddelbuettel commented Sep 14, 2016 edited

Same with many European formats which do, say, %d.%m.%Y.

But this (famously) clashes with what North America does in its (braindead, but prevalent) %m/%d/%Y -- modulo the separators. There is no way to deal with the safely -- hence everybody's preference for ISO formats -- and strptime() et al have the same issue. I am not sure localization can help.

You can pre-load formats in the next version:

R> anytime:::addFormat("%d.%m.%Y") # Europe
R> anytime("10.11.2012")
[1] "2012-11-10 CST"
R> 

If you can work out how localization could help at the C++ level offered by Boost I'd be interested. Otherwise it is the "same old" issue also plagueing strptime() et al, and there is little I can do.

@eddelbuettel
Owner

Good news: Boost has %x for locale-dependent input, see the docs.

I plan to test that.

@eddelbuettel
Owner

Format strings can now be added.

@adisarid

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment