Files
rsh26_pool_example/test/rsh26pool/jst_test.exs
T

62 lines
1.9 KiB
Elixir
Raw Normal View History

2026-07-04 19:27:17 +09:00
defmodule Rsh26pool.JSTTest do
use ExUnit.Case, async: true
alias Rsh26pool.JST
describe "parse_local/1" do
test "interprets the input as wall-clock JST and returns UTC (-9h)" do
assert JST.parse_local("2026-07-04T18:00") == {:ok, ~U[2026-07-04 09:00:00Z]}
end
test "accepts a value that already carries seconds" do
assert JST.parse_local("2026-07-04T18:00:30") == {:ok, ~U[2026-07-04 09:00:30Z]}
end
test "shifts across the date boundary when JST wall time is early morning" do
# 2026-07-04 05:00 JST is the previous UTC day at 20:00.
assert JST.parse_local("2026-07-04T05:00") == {:ok, ~U[2026-07-03 20:00:00Z]}
end
test "returns :error on unparseable text" do
assert JST.parse_local("garbage") == :error
end
test "returns :error for non-binary input" do
assert JST.parse_local(nil) == :error
assert JST.parse_local(1234) == :error
end
end
describe "to_local/1 and format/1" do
test "to_local shifts a stored UTC datetime forward by 9 hours" do
assert JST.to_local(~U[2026-07-04 09:00:00Z]) == ~U[2026-07-04 18:00:00Z]
end
test "format renders the stored UTC datetime as JST wall time" do
assert JST.format(~U[2026-07-04 09:00:00Z]) == "2026/07/04 18:00"
end
test "format(nil) is the empty string" do
assert JST.format(nil) == ""
end
end
describe "parse_local |> format round-trip" do
test "is the identity on the wall clock at minute precision" do
wall_times = [
"2026-07-04T18:00",
"2026-01-01T00:00",
"2026-12-31T23:59",
"2026-03-15T09:05",
"2026-07-04T05:00"
]
for wall <- wall_times do
assert {:ok, utc} = JST.parse_local(wall)
expected = wall |> String.replace("-", "/") |> String.replace("T", " ")
assert JST.format(utc) == expected
end
end
end
end