This repository has been archived by the owner on May 14, 2018. It is now read-only.
forked from quantum-elixir/quantum-core
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quantum-elixir#81 from kaiatgithub/master
modify Quantum.Timer to use correct timezone function. fixes quantum-elixir#73
- Loading branch information
Showing
2 changed files
with
41 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule Quantum.TimerTest do | ||
use ExUnit.Case | ||
|
||
test "tick function returns correct time when timezone is set" do | ||
current_time_zone = Application.get_env(:quantum, :timezone, :utc) | ||
|
||
Application.put_env(:quantum, :timezone, :utc) | ||
{d_utc, {h_utc, m_utc, _}} = :calendar.now_to_universal_time(:os.timestamp) | ||
assert Quantum.Timer.tick == {d_utc, h_utc, m_utc} | ||
|
||
Application.put_env(:quantum, :timezone, :local) | ||
{d_local, {h_local, m_local, _}} = :calendar.now_to_local_time(:os.timestamp) | ||
assert Quantum.Timer.tick == {d_local, h_local, m_local} | ||
|
||
Application.put_env(:quantum, :timezone, current_time_zone) | ||
end | ||
|
||
test "timezone_function function raises error when timezone is set incorrectly" do | ||
current_time_zone = Application.get_env(:quantum, :timezone, :utc) | ||
|
||
try do | ||
Application.put_env(:quantum, :timezone, "test-time-zone") | ||
assert_raise RuntimeError, "Unsupported timezone: test-time-zone", fn -> | ||
Quantum.Timer.timezone_function | ||
end | ||
after | ||
Application.put_env(:quantum, :timezone, current_time_zone) | ||
end | ||
end | ||
|
||
end |