forked from quantum-elixir/quantum-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate_library_test.exs
41 lines (33 loc) · 1.1 KB
/
date_library_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
defmodule Quantum.DateLibraryTest do
use ExUnit.Case, async: true
alias Quantum.DateLibrary
describe "to_tz!/2" do
test "shifts zone" do
date = ~N[2015-01-01 01:00:00]
expected = ~N[2015-01-01 02:00:00]
assert DateLibrary.to_tz!(date, "Europe/Copenhagen") == expected
end
test "errors with invalid timezone" do
assert_raise Quantum.DateLibrary.InvalidTimezoneError, fn ->
DateLibrary.to_tz!(~N[2018-03-25 02:00:00], "Foobar")
end
end
end
describe "to_utc!/2" do
test "shifts zone" do
date = ~N[2015-01-01 02:00:00]
expected = ~N[2015-01-01 01:00:00]
assert DateLibrary.to_utc!(date, "Europe/Copenhagen") == expected
end
test "detects non-existent times" do
assert_raise Quantum.DateLibrary.InvalidDateTimeForTimezoneError, fn ->
DateLibrary.to_utc!(~N[2018-03-25 02:00:00], "Europe/Zurich")
end
end
test "errors with invalid timezone" do
assert_raise Quantum.DateLibrary.InvalidTimezoneError, fn ->
DateLibrary.to_utc!(~N[2018-03-25 02:00:00], "Foobar")
end
end
end
end