r-lib/clock

add utc_offset parameter to date_time_parse()

reikoch opened this issue · 5 comments

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.

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"

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.

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

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

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.