@@ -3,31 +3,32 @@ format_timestamp <- function(indf, index = 1) {
33 return (indf )
44 }
55 if (stringr :: str_detect(indf [[index ]][1 ], " ^\\ d{4}-\\ d{2}-\\ d{2} \\ d{2}:\\ d{2}:\\ d{2} \\ +\\ d{4}$" )) {
6- indf [[index ]] <- as.POSIXct( strptime(indf [[index ]], format = " %Y-%m-%d %H:%M:%S" , tz = " UTC" ) )
6+ indf [[index ]] <- strptime(indf [[index ]], format = " %Y-%m-%d %H:%M:%S" , tz = " UTC" )
77 }
88 else if (stringr :: str_detect(indf [[index ]][1 ], " ^\\ d{4}-\\ d{2}-\\ d{2} \\ d{2}:\\ d{2}:\\ d{2}$" )) {
9- indf [[index ]] <- as.POSIXct( strptime(indf [[index ]], format = " %Y-%m-%d %H:%M:%S" , tz = " UTC" ) )
9+ indf [[index ]] <- strptime(indf [[index ]], format = " %Y-%m-%d %H:%M:%S" , tz = " UTC" )
1010 }
1111 else if (stringr :: str_detect(indf [[index ]][1 ], " ^\\ d{4}-\\ d{2}-\\ d{2} \\ d{2}:\\ d{2}$" )) {
12- indf [[index ]] <- as.POSIXct( strptime(indf [[index ]], format = " %Y-%m-%d %H:%M" , tz = " UTC" ) )
12+ indf [[index ]] <- strptime(indf [[index ]], format = " %Y-%m-%d %H:%M" , tz = " UTC" )
1313 }
1414 else if (stringr :: str_detect(indf [[index ]][1 ], " ^\\ d{2}/\\ d{2}/\\ d{2}$" )) {
15- indf [[index ]] <- as.POSIXct( strptime(indf [[index ]], format = " %m/%d/%y" , tz = " UTC" ) )
15+ indf [[index ]] <- strptime(indf [[index ]], format = " %m/%d/%y" , tz = " UTC" )
1616 }
1717 else if (stringr :: str_detect(indf [[index ]][1 ], " ^\\ d{2}/\\ d{2}/\\ d{4}$" )) {
18- indf [[index ]] <- as.POSIXct( strptime(indf [[index ]], format = " %m/%d/%Y" , tz = " UTC" ) )
18+ indf [[index ]] <- strptime(indf [[index ]], format = " %m/%d/%Y" , tz = " UTC" )
1919 }
2020 else if (stringr :: str_detect(indf [[index ]][1 ], " ^\\ d{4}\\ d{2}\\ d{2}$" )) {
21- indf [[index ]] <- as.POSIXct( strptime(indf [[index ]], format = " %Y%m%d" , tz = " UTC" ) )
21+ indf [[index ]] <- strptime(indf [[index ]], format = " %Y%m%d" , tz = " UTC" )
2222 }
2323 else if (stringr :: str_detect(indf [[index ]][1 ], " ^\\ d{4}/\\ d{2}/\\ d{2}/\\ d{2}$" )) {
24- indf [[index ]] <- as.POSIXct( strptime(indf [[index ]], format = " %Y/%m/%d/%H" , tz = " UTC" ) )
24+ indf [[index ]] <- strptime(indf [[index ]], format = " %Y/%m/%d/%H" , tz = " UTC" )
2525 }
2626 else if (stringr :: str_detect(indf [[index ]][1 ], " ^\\ d{10}$" )) {
2727 # Handle Unix seconds in milliseconds
28- indf [[index ]] <- as.POSIXct(as. POSIXlt(indf [[index ]], origin = " 1970-01-01" , tz = " UTC" ) )
28+ indf [[index ]] <- as.POSIXlt(indf [[index ]], origin = " 1970-01-01" , tz = " UTC" )
2929 }
3030
31+ indf [[index ]] <- as.POSIXct(indf [[index ]], tz = " UTC" )
3132 return (indf )
3233}
3334
0 commit comments