Skip to content

Commit 59e7cda

Browse files
author
José Valim
committed
Include abbreviation in DateTime.to_string/1
1 parent 5253737 commit 59e7cda

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

lib/elixir/lib/calendar.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ defmodule DateTime do
11841184
...> hour: 23, minute: 0, second: 7, microsecond: {0, 0},
11851185
...> utc_offset: 3600, std_offset: 3600, time_zone: "Europe/Warsaw"}
11861186
iex> DateTime.to_string(dt)
1187-
"2000-02-29 23:00:07+02:00 Europe/Warsaw"
1187+
"2000-02-29 23:00:07+02:00 CEST Europe/Warsaw"
11881188
11891189
iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "UTC",
11901190
...> hour: 23, minute: 0, second: 7, microsecond: {0, 0},
@@ -1196,7 +1196,7 @@ defmodule DateTime do
11961196
...> hour: 23, minute: 0, second: 7, microsecond: {0, 0},
11971197
...> utc_offset: -12600, std_offset: 3600, time_zone: "Brazil/Manaus"}
11981198
iex> DateTime.to_string(dt)
1199-
"2000-02-29 23:00:07-02:30 Brazil/Manaus"
1199+
"2000-02-29 23:00:07-02:30 BRM Brazil/Manaus"
12001200
"""
12011201
@spec to_string(DateTime.t) :: String.t
12021202
def to_string(%DateTime{calendar: calendar} = dt) do

lib/elixir/lib/calendar/iso.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ defmodule Calendar.ISO do
7575
date_to_string(year, month, day) <> " " <> time_to_string(hour, minute, second, microsecond)
7676
end
7777

78-
def to_string(%DateTime{year: year, month: month, day: day,
78+
def to_string(%DateTime{year: year, month: month, day: day, zone_abbr: zone_abbr,
7979
hour: hour, minute: minute, second: second, microsecond: microsecond,
8080
utc_offset: utc_offset, std_offset: std_offset, time_zone: time_zone}) do
8181
date_to_string(year, month, day) <> " " <>
8282
time_to_string(hour, minute, second, microsecond) <>
8383
offset_to_string(utc_offset, std_offset, time_zone) <>
84-
zone_to_string(utc_offset, std_offset, time_zone)
84+
zone_to_string(utc_offset, std_offset, zone_abbr, time_zone)
8585
end
8686

8787
defp date_to_string(year, month, day) do
@@ -108,8 +108,8 @@ defmodule Calendar.ISO do
108108
sign(total) <> zero_pad(hour, 2) <> ":" <> zero_pad(minute, 2)
109109
end
110110

111-
defp zone_to_string(0, 0, "Etc/UTC"), do: ""
112-
defp zone_to_string(_, _, zone), do: " " <> zone
111+
defp zone_to_string(0, 0, _abbr, "Etc/UTC"), do: ""
112+
defp zone_to_string(_, _, abbr, zone), do: " " <> abbr <> " " <> zone
113113

114114
defp sign(total) when total < 0, do: "-"
115115
defp sign(_), do: "+"

lib/elixir/test/elixir/calendar_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ defmodule DateTimeTest do
6464
dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "BRM",
6565
hour: 23, minute: 0, second: 7, microsecond: {0, 0},
6666
utc_offset: -12600, std_offset: 3600, time_zone: "Brazil/Manaus"}
67-
assert to_string(dt) == "2000-02-29 23:00:07-02:30 Brazil/Manaus"
67+
assert to_string(dt) == "2000-02-29 23:00:07-02:30 BRM Brazil/Manaus"
6868
end
6969
end

0 commit comments

Comments
 (0)