Skip to content

Commit 3530430

Browse files
committed
Rewrite timezone support
1 parent babdd4b commit 3530430

19 files changed

+6434
-2488
lines changed

.github/workflows/ci.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ jobs:
1414
MIX_ENV: test
1515
CI: "true"
1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
1818
- uses: erlef/setup-beam@v1
1919
with:
2020
otp-version: '25'
21-
elixir-version: '1.14.0'
21+
elixir-version: '1.14.3'
2222
- run: mix deps.get --only dev
2323
- run: mix format --check-formatted
2424
- run: mix credo --strict
2525

2626
test-oldest:
27-
runs-on: ubuntu-18.04
27+
runs-on: ubuntu-20.04
2828
name: Tests on oldest version
2929
env:
3030
MIX_ENV: test
3131
CI: "true"
3232
steps:
33-
- uses: actions/checkout@v2
33+
- uses: actions/checkout@v3
3434
- uses: erlef/setup-beam@v1
3535
with:
36-
otp-version: '19'
37-
elixir-version: '1.4.5'
36+
otp-version: '21'
37+
elixir-version: '1.11.4'
3838
- run: rm mix.lock
3939
- run: mix deps.get
4040
- run: mix compile --force --warnings-as-errors
@@ -47,11 +47,11 @@ jobs:
4747
MIX_ENV: test
4848
CI: "true"
4949
steps:
50-
- uses: actions/checkout@v2
50+
- uses: actions/checkout@v3
5151
- uses: erlef/setup-beam@v1
5252
with:
5353
otp-version: '25'
54-
elixir-version: '1.14.0'
54+
elixir-version: '1.14.3'
5555
- run: rm mix.lock
5656
- run: mix deps.get
5757
- run: mix compile --force --warnings-as-errors

CHANGELOG.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

3-
## 1.1.5
3+
## 1.2.0 (unreleased)
4+
5+
- Drop Timex as dependency. This required a custom IANA file parser for
6+
determining timezones and rules that was able to parse timezone abbreviations.
7+
Doing so requires the use of Elixir functions introduced in Elixir 1.11.
8+
9+
## 1.1.5 (2022-10-07)
410

511
- Switch to pre-compiled combinators so that NimbleParsec is not needed during
612
compilation-- why have everyone else compile this when we can compile it
@@ -12,18 +18,18 @@
1218
fallback `assume_date` since there is not a data structure that only describes
1319
Month and Year in Elixir.
1420

15-
## 1.1.4
21+
## 1.1.4 (2022-10-05)
1622

1723
- Update GitHub Repo references
1824

19-
## 1.1.3
25+
## 1.1.3 (2021-10-24)
2026

2127
- Stricter time parsing by requiring time separators. For example, `949` used to
2228
be parsed as `09:49:00`, but is now considered not valid. This is to help
2329
decrease false positives of nonsensical times such as `25:00 am` (incorrectly
2430
parsed as `02:05:00`). Thanks @fcapovilla (PR #46)
2531

26-
## 1.1.2
32+
## 1.1.2 (2021-06-14)
2733

2834
- Correct handling of 12:xx:xx AM timestamps (12hr). These were incorrectly
2935
parsed as 12:xx:xx (24hr) timestamps when they should have been 00:xx:xx
@@ -32,19 +38,19 @@
3238
- Lock Timex to >= 3.2.1 and <= 3.7.2 to avoid timezone conversion issues when
3339
using `to_utc: true`. Looks like there are some breaking changes (for us)
3440

35-
## 1.1.1
41+
## 1.1.1 (2021-02-06)
3642

3743
- Adjust tokenizer to prefer month/day before of day/month when those are the
3844
only found tokens. Thanks @mwean raising the issue.
3945

40-
## 1.1.0
46+
## 1.1.0 (2020-10-17)
4147

4248
- Add option `use_1904_date_system` for the serial parser. It defaults to
4349
`false`. Most spreadsheet applications use the 1900 date system, but
4450
Microsoft Excel on Macintosh in particular used the 1904 date system
4551
[@fcapovilla].
4652

47-
## 1.0.0
53+
## 1.0.0 (2020-02-05)
4854

4955
### Breaking
5056

@@ -84,32 +90,32 @@
8490
- Added `parsers: []` option to add or disable parsers. This is helpful if you
8591
are don't want to consider Serial or Epoch timestamps.
8692

87-
## 0.2.0
93+
## 0.2.0 (2019-09-26)
8894

8995
- Add Serial time support
9096

91-
## 0.1.4
97+
## 0.1.4 (2019-09-03)
9298

9399
- Refactor
94100
- Support subsecond parsing to 24 digits (yoctoseconds) [thanks @myfreeweb]
95101

96-
## 0.1.3
102+
## 0.1.3 (2019-08-02)
97103

98104
- Support parsing Unix epoch times from strings
99105
- Fix microsecond parsing
100106

101-
## 0.1.2
107+
## 0.1.2 (2019-07-11)
102108

103109
- Validate days of month. Previously it would allow invalid days such as Feb 30.
104110
Now it will check if the year is a leap year and allow up to 29, and otherwise
105111
28 for Feb. It will also reject day 31 on months without 31 days.
106112

107-
## 0.1.1
113+
## 0.1.1 (2019-07-03)
108114

109115
- Fix PM 12-hr conversion. The bug would convert 12:34PM to 24:34 which is
110116
not valid
111117

112-
## 0.1.0
118+
## 0.1.0 (2019-06-24)
113119

114120
- Add DateTimeParser.parse_datetime/2
115121
- Add DateTimeParser.parse_date/1

EXAMPLES.livemd

+3-1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ convert to UTC or to assume a time when not present.
227227
|`2016/1/9`|`2016-01-09`|parse| |
228228
|`2017-02-29`|`Could not parse "2017-02-29"`|parse_date| |
229229
|`2017-02-29 00:00:00 UTC`|`Could not parse "2017-02-29 00:00:00 UTC"`|parse_datetime| |
230+
|`2017-03-04 15:20:47 EDT`|`2017-03-04T20:20:47Z`|parse_datetime|`[to_utc: true]`|
231+
|`2017-03-04 15:20:47 EST`|`2017-03-04T20:20:47Z`|parse_datetime|`[to_utc: true]`|
230232
|`2017-04-31`|`Could not parse "2017-04-31"`|parse_date| |
231233
|`2017-04-31 00:00:00 UTC`|`Could not parse "2017-04-31 00:00:00 UTC"`|parse_datetime| |
232234
|`2017-06-31`|`Could not parse "2017-06-31"`|parse_date| |
@@ -239,7 +241,7 @@ convert to UTC or to assume a time when not present.
239241
|`2017-11-04 15:20:47 EDT`|`2017-11-04`|parse_date| |
240242
|`2017-11-04 15:20:47 EDT`|`2017-11-04T19:20:47Z`|parse_datetime|`[to_utc: true]`|
241243
|`2017-11-04 15:20:47 EST`|`2017-11-04`|parse_date| |
242-
|`2017-11-04 15:20:47 EST`|`2017-11-04T20:20:47Z`|parse_datetime|`[to_utc: true]`|
244+
|`2017-11-04 15:20:47 EST`|`2017-11-04T19:20:47Z`|parse_datetime|`[to_utc: true]`|
243245
|`2017-11-04 15:20:47 UTC`|`2017-11-04`|parse_date| |
244246
|`2017-11-04 15:20:47 UTC`|`2017-11-04T15:20:47Z`|parse_datetime| |
245247
|`2017-11-04 15:20:47+0000`|`2017-11-04`|parse_date| |

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ iex> DateTimeParser.parse_datetime(~s|"Mar 28, 2018 7:39:53 AM PDT"|, to_utc: tr
111111

112112
iex> {:ok, datetime} = DateTimeParser.parse_datetime(~s|"Mar 1, 2018 7:39:53 AM PST"|)
113113
iex> datetime
114-
#DateTime<2018-03-01 07:39:53-08:00 PST PST8PDT>
114+
#DateTime<2018-03-01 07:39:53-08:00 PST America/Los_Angeles>
115115

116116
iex> DateTimeParser.parse_datetime(~s|"Mar 1, 2018 7:39:53 AM PST"|, to_utc: true)
117117
{:ok, DateTime.from_naive!(~N[2018-03-01T15:39:53Z], "Etc/UTC")}
118118

119119
iex> {:ok, datetime} = DateTimeParser.parse_datetime(~s|"Mar 28, 2018 7:39:53 AM PDT"|)
120120
iex> datetime
121-
#DateTime<2018-03-28 07:39:53-07:00 PDT PST8PDT>
121+
#DateTime<2018-03-28 07:39:53-07:00 PDT America/Los_Angeles>
122122

123123
iex> DateTimeParser.parse_time("10:13pm")
124124
{:ok, ~T[22:13:00]}
@@ -147,6 +147,9 @@ end
147147

148148
## Configuration
149149

150+
You must have a timezone database configured if you want parsing to consider
151+
timezones. See [tz](https://github.com/mathieuprog/tz) or [tzdata](https://github.com/lau/tzdata).
152+
150153
```elixir
151154
# This is the default config
152155
alias DateTimeParser.Parser
@@ -155,6 +158,9 @@ config :date_time_parser, parsers: [Parser.Epoch, Parser.Serial, Parser.Tokenize
155158
# To enable only specific parsers, include them in the :parsers key.
156159
config :date_time_parser, parsers: [Parser.Tokenizer]
157160

161+
# Adding the timezone database from Tz
162+
config :elixir, :time_zone_database, Tz.TimeZoneDatabase
163+
158164
# Or in runtime, pass in the parsers in the function.
159165
DateTimeParser.parse(mystring, parsers: [Parser.Tokenizer])
160166
```

bin/release

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ mix tests
99
git add EXAMPLES.livemd
1010
git add lib/combinators.ex
1111

12-
sed -i "s/$previous_version/$release_version/" README.md
13-
sed -i "s/$previous_version/$release_version/" mix.exs
14-
sed -i "s/unreleased/$release_version/" CHANGELOG.md
12+
sed -i "" "s/$previous_version/$release_version/" README.md
13+
sed -i "" "s/$previous_version/$release_version/" mix.exs
14+
sed -i "" "s/unreleased/$release_version ($(date +%F))/" CHANGELOG.md
1515
git add mix.exs
1616
git add README.md
1717
git add CHANGELOG.md

config/config.exs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Config
2+
import_config "#{config_env()}.exs"

config/dev.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Config
2+
3+
config :elixir, :time_zone_database, Tz.TimeZoneDatabase

config/test.exs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Config
2+
config :elixir, :time_zone_database, Tz.TimeZoneDatabase

0 commit comments

Comments
 (0)