rstudio / blastula

Easily send great-looking HTML email messages from R
https://pkgs.rstudio.com/blastula
Other
546 stars 84 forks source link

blastula::add_readable_time() converts all times to the 12 hour format, even if I change the locale #308

Open alsmnn opened 1 year ago

alsmnn commented 1 year ago

Because of this formatting option time will always be reduced to the 12 hour format. The typical 24 hour format can't be accomplished with this. https://github.com/rstudio/blastula/blob/cdf155be9b821a8e5fed43e3b159baec48bb97be/R/add_readable_time.R#L69 Even changing locale does not work:

withr::with_locale(c("LC_TIME" = "de_DE.UTF-8"), blastula::add_readable_time())
[1] "Mittwoch, Juli 12, 2023 at 5:26  (CEST)"

In this case the result should have been : [1] "Mittwoch, Juli 12, 2023 at 17:26 (CEST)"

which could have been achieved by using %H in the format call: gsub(" |^0", "", format(time, "%H:%M")), But because of the next line this does not work very well. https://github.com/rstudio/blastula/blob/cdf155be9b821a8e5fed43e3b159baec48bb97be/R/add_readable_time.R#L70 You will get an extra space, because 24 hour based formats don't have the option %p. As you can see, there are two spaces between 5:26 and (CEST) (v0.3.2 currently installed and in v0.3.3 it would be 05:26 (CEST))

> withr::with_locale(c("LC_TIME" = "en_US.UTF-8"), blastula::add_readable_time())
[1] "Wednesday, July 12, 2023 at 5:26 PM (CEST)"

In the second case PM is added, because of the locale, which is correct.