Skip to content

Commit 1fc0481

Browse files
committed
Correct example and code formatting of DateTime.to_unix/2
1 parent 96afdd9 commit 1fc0481

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/elixir/lib/calendar.ex

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,19 +1067,21 @@ defmodule DateTime do
10671067
iex> 1464096368 |> DateTime.from_unix!() |> DateTime.to_unix()
10681068
1464096368
10691069
1070-
iex> %DateTime{calendar: Calendar.ISO, day: 20, hour: 18, microsecond: {273806, 6}, minute: 58,
1071-
...> month: 11, second: 19, time_zone: "America/Montevideo",
1072-
...> utc_offset: -10800, std_offset: 3600, year: 2014, zone_abbr: "UYST"}
1073-
...> |> DateTime.to_unix()
1070+
iex> dt = %DateTime{calendar: Calendar.ISO, day: 20, hour: 18, microsecond: {273806, 6},
1071+
...> minute: 58, month: 11, second: 19, time_zone: "America/Montevideo",
1072+
...> utc_offset: -10800, std_offset: 3600, year: 2014, zone_abbr: "UYST"}
1073+
iex> DateTime.to_unix(dt)
10741074
1416517099
1075+
10751076
"""
10761077
@spec to_unix(DateTime.t, System.time_unit) :: non_neg_integer
10771078
def to_unix(%DateTime{std_offset: std_offset, utc_offset: utc_offset,
10781079
hour: hour, minute: minute, second: second, microsecond: {microsecond, _},
10791080
year: year, month: month, day: day}, unit \\ :seconds) when year >= 1970 do
1080-
seconds = :calendar.datetime_to_gregorian_seconds({{year, month, day}, {hour, minute, second}})
1081-
|> Kernel.-(utc_offset)
1082-
|> Kernel.-(std_offset)
1081+
seconds =
1082+
:calendar.datetime_to_gregorian_seconds({{year, month, day}, {hour, minute, second}})
1083+
|> Kernel.-(utc_offset)
1084+
|> Kernel.-(std_offset)
10831085
System.convert_time_unit((seconds - @unix_epoch) * 1_000_000 + microsecond, :microseconds, unit)
10841086
end
10851087

0 commit comments

Comments
 (0)