JBGruber / rwhatsapp

An R package for working with WhatsApp data 💬
94 stars 19 forks source link

Date time format for French conversations #8

Closed abichat closed 4 years ago

abichat commented 4 years ago

I encountered an issue to parse WhatsApp data with French locale.

Warning message:
In rwa_read(x = "Discussion WhatsApp avec XXX.txt") :
  Time conversion did not work correctly. Provide a custom format or add an issue at www.github.com/JBGruber/rwhatsapp.

This is what French data look like:

26/09/2019 à 22:39 - Les messages envoyés dans cette discussion et les appels sont désormais protégés avec le chiffrement de bout en bout. Appuyez pour plus d'informations.
26/09/2019 à 22:39 - XXX: Salut :)
26/09/2019 à 22:39 - AB: Salut XXX :)

I tried to specified format = "dd/MM/yyyy à hh:mm" (and others) in rwa_read() but it did not work... Do you have an idea of the correct format to use? If found, maybe it could be added to the default formats in rwa_parse_time().

JBGruber commented 4 years ago

Yes, you can use this format:

x <- c("26/09/2019 à 22:39 - Les messages envoyés dans cette discussion et les appels sont désormais protégés avec le chiffrement de bout en bout. Appuyez pour plus d'informations.",
       "26/09/2019 à 22:39 - XXX: Salut :)",
       "26/09/2019 à 22:39 - AB: Salut XXX :)")
rwhatsapp::rwa_read(x, format = "dd/MM/yyyy 'à' HH:mm")
#> # A tibble: 3 x 6
#>   time                author text                       source  emoji emoji_name
#>   <dttm>              <fct>  <chr>                      <chr>   <lis> <list>    
#> 1 2019-09-26 22:39:51 <NA>   Les messages envoyés dans… text i… <NUL… <NULL>    
#> 2 2019-09-26 22:39:51 XXX    Salut :)                   text i… <NUL… <NULL>    
#> 3 2019-09-26 22:39:51 AB     Salut XXX :)               text i… <NUL… <NULL>

Created on 2019-12-19 by the reprex package (v0.3.0)

Under the hood, stri_datetime_parse() is used for date conversion (see ?stringi::stri_datetime_parse()). I will leave this open to see if I can integrate it into the automatic format detection.

abichat commented 4 years ago

Actually, the issue came from the hh instead of HH 😅 On my computer, it works with "dd/MM/yyyy à HH:mm" Thanks!

JBGruber commented 4 years ago

This works now without defining a custom format. But the update didn't make it into the new CRAN version. Install with remotes::install_github("JBGruber/rwhatsapp") and try again.

x <- c("26/09/2019 à 22:39 - Les messages envoyés dans cette discussion et les appels sont désormais protégés avec le chiffrement de bout en bout. Appuyez pour plus d'informations.",
       "26/09/2019 à 22:39 - XXX: Salut :)",
       "26/09/2019 à 22:39 - AB: Salut XXX :)")

rwhatsapp::rwa_read(x)
#> # A tibble: 3 x 6
#>   time                author text                       source  emoji emoji_name
#>   <dttm>              <fct>  <chr>                      <chr>   <lis> <list>    
#> 1 2019-09-26 22:39:38 <NA>   Les messages envoyés dans… text i… <NUL… <NULL>    
#> 2 2019-09-26 22:39:38 XXX    Salut :)                   text i… <NUL… <NULL>    
#> 3 2019-09-26 22:39:38 AB     Salut XXX :)               text i… <NUL… <NULL>

Created on 2019-12-22 by the reprex package (v0.3.0)