relvacode / iso8601

A fast ISO8601 date parser for Go
MIT License
144 stars 16 forks source link

Support parsing with timezone location similar to time.ParseInLocation and detect timezone presence in string #25

Open indexjoseph opened 3 months ago

indexjoseph commented 3 months ago

Is your feature request related to a problem? Please describe.

Currently, in #3008 we're trying to use this ISO8601 library to allow a user to specify a start and end time, but we also have a timezone field. Preferably when the user is using ISO8601 format we'd like them to specify it without a timezone (e.g. 2024-07-08T16:36:59) and specify a timezone in the designated .timezone field. However if they choose to specify a timezone in the start and/or end time and a timezone field value then we'd like for that start/end time's timezone to override the timezone field, thus we need a way to determine whether or not the formatted string has a timezone.

With the current implementation parsing defaults the timezone to UTC and doesn't allow users to specify a timezone. A function similar to the time library's ParseInLocation would allow for us to parse the ISO8601 time in a specified zone. In addition a way to allow us to determine whether or not the user specified a timezone in the ISO8601 formatted string (e.g., 2024-07-08T12:19:50.1-04:00, where -04:00 is the offset/timezone), this would allow us determine whether we should be parsing with the timezone field.

Describe alternatives you've considered

An alternative approach would be to take the parsed ISO8601 time provided and use time.Date() to place it in the correct timezone after it's parsed (instead of the default UTC).

indexjoseph commented 3 months ago

We've come up with a solution that no longer requires ISO8601 format, however, I still believe a ParseInLocation function would be a nice-to-have for this library.