feat(rules): add an opt-in timezone rule (#23)

common.Timezone matches UTC and GMT with an optional offset (UTC+2,
GMT-05:30, GMT+0530) and a small table of upper case abbreviations
(EST, PDT, CET, ...), and sets Context.Location, so "10 pm EST" comes back
as 22:00 in a -05:00 zone. A timezone alone does not count as a match.
It is not added to common.All, so existing parsers behave as before.
This commit is contained in:
dualfroz committed 2026-10-03 02:49:55 +02:00
1 parent c0f903d615
commit fa0fa5b55b
3 files changed
+138

No files matched your search

+10
View File
@@ -103,6 +103,16 @@ fmt.Printf(r.Time.String())
// 13:46:21 (correct)
```
#### Timezones
The timezone rule is not part of `common.All`, add it to have `10 pm EST` or `22:00 UTC+2` returned in that zone:
```go
w.Add(common.Timezone(rules.Override))
```
It knows `UTC` and `GMT` with an optional offset (`GMT-05:30`, `UTC+0530`) and a few upper case abbreviations (`EST`, `PDT`, `CET`, ...), each as a fixed offset.
### State of the project
The project is in a more-or-less complete state. It's used for one project already. Bugs will be fixed as soon as they will be found.