r-lib / clock

A Date-Time Library for R
https://clock.r-lib.org
Other
97 stars 4 forks source link

add utc_offset parameter to date_time_parse() #311

Closed reikoch closed 1 year ago

reikoch commented 1 year ago

In meteorology stations often do not specify their timezone but the UTC offset. It would be nice if date_time_parse() would accept a parameter "utc_offset", alternative to "zone", for specifying the relation to UTC.

trevorld commented 1 year ago

FYI: You can use date_time_parse_RFC_3339() instead (which supports parsing date times with UTC offsets)

library("clock")
date_time_parse_RFC_3339("2020-01-02T03:04:05-07:00", offset = "%Ez")
[1] "2020-01-02 10:04:05 UTC"
reikoch commented 1 year ago

If I had the utc offset as part of the text to read - yes. But I normally just get input like "2020-01-02T03:04" and separately the offset.

trevorld commented 1 year ago

You could use paste0() to combine them into one string e.g. datetime_parse_RFC_3339(paste0(datetime, offset), offset = "%Ez")

reikoch commented 1 year ago

True, but with millions of rows in a text file this is not very practical :-(

DavisVaughan commented 1 year ago

I think it is reasonable to require that the offset be part of the text string, since the offset is typically vectorized to account for daylight saving time adjustments. paste0() will be fast even with millions of rows.