@@ -1237,11 +1237,19 @@ defmodule Calendar.ISO do
12371237
12381238 ## Examples
12391239
1240- iex> Calendar.ISO.time_to_iodata(2, 2, 2, {2, 6})
1241- [[["0", "2"], 58, ["0", "2"], 58, ["0", "2"]], 46, ["00000", "2"]]
1240+ iex> data = Calendar.ISO.time_to_iodata(2, 2, 2, {2, 6})
1241+ iex> IO.iodata_to_binary(data)
1242+ "02:02:02.000002"
12421243
12431244 """
12441245 @ doc since: "1.19.0"
1246+ @ spec time_to_iodata (
1247+ Calendar . hour ( ) ,
1248+ Calendar . minute ( ) ,
1249+ Calendar . second ( ) ,
1250+ Calendar . microsecond ( ) ,
1251+ :basic | :extended
1252+ ) :: iodata
12451253 def time_to_iodata (
12461254 hour ,
12471255 minute ,
@@ -1261,15 +1269,16 @@ defmodule Calendar.ISO do
12611269 defp time_to_iodata_guarded ( hour , minute , second , { microsecond , precision } , format ) do
12621270 [
12631271 time_to_iodata_format ( hour , minute , second , format ) ,
1264- ?. ,
1265- microseconds_to_iodata ( microsecond , precision )
1272+ ?.
1273+ | microseconds_to_iodata ( microsecond , precision )
12661274 ]
12671275 end
12681276
1269- defp microseconds_to_iodata ( _microsecond , 0 ) , do: [ ]
1270- defp microseconds_to_iodata ( microsecond , 6 ) , do: zero_pad ( microsecond , 6 )
1277+ @ doc false
1278+ def microseconds_to_iodata ( _microsecond , 0 ) , do: [ ]
1279+ def microseconds_to_iodata ( microsecond , 6 ) , do: zero_pad ( microsecond , 6 )
12711280
1272- defp microseconds_to_iodata ( microsecond , precision ) do
1281+ def microseconds_to_iodata ( microsecond , precision ) do
12731282 num = div ( microsecond , div_factor ( precision ) )
12741283 zero_pad ( num , precision )
12751284 end
@@ -1281,11 +1290,11 @@ defmodule Calendar.ISO do
12811290 defp div_factor ( 5 ) , do: 10
12821291
12831292 defp time_to_iodata_format ( hour , minute , second , :extended ) do
1284- [ zero_pad ( hour , 2 ) , ?: , zero_pad ( minute , 2 ) , ?: , zero_pad ( second , 2 ) ]
1293+ [ zero_pad ( hour , 2 ) , ?: , zero_pad ( minute , 2 ) , ?: | zero_pad ( second , 2 ) ]
12851294 end
12861295
12871296 defp time_to_iodata_format ( hour , minute , second , :basic ) do
1288- [ zero_pad ( hour , 2 ) , zero_pad ( minute , 2 ) , zero_pad ( second , 2 ) ]
1297+ [ zero_pad ( hour , 2 ) , zero_pad ( minute , 2 ) | zero_pad ( second , 2 ) ]
12891298 end
12901299
12911300 @ doc """
@@ -1324,8 +1333,9 @@ defmodule Calendar.ISO do
13241333
13251334 ## Examples
13261335
1327- iex> Calendar.ISO.date_to_iodata(2015, 2, 28)
1328- ["2015", 45, ["0", "2"], 45, "28"]
1336+ iex> data = Calendar.ISO.date_to_iodata(2015, 2, 28)
1337+ iex> IO.iodata_to_binary(data)
1338+ "2015-02-28"
13291339 """
13301340 @ doc since: "1.19.0"
13311341 @ spec date_to_iodata ( year , month , day , :basic | :extended ) :: iodata
@@ -1336,11 +1346,11 @@ defmodule Calendar.ISO do
13361346 end
13371347
13381348 defp date_to_iodata_guarded ( year , month , day , :extended ) do
1339- [ zero_pad ( year , 4 ) , ?- , zero_pad ( month , 2 ) , ?- , zero_pad ( day , 2 ) ]
1349+ [ zero_pad ( year , 4 ) , ?- , zero_pad ( month , 2 ) , ?- | zero_pad ( day , 2 ) ]
13401350 end
13411351
13421352 defp date_to_iodata_guarded ( year , month , day , :basic ) do
1343- [ zero_pad ( year , 4 ) , zero_pad ( month , 2 ) , zero_pad ( day , 2 ) ]
1353+ [ zero_pad ( year , 4 ) , zero_pad ( month , 2 ) | zero_pad ( day , 2 ) ]
13441354 end
13451355
13461356 @ doc """
@@ -1402,11 +1412,26 @@ defmodule Calendar.ISO do
14021412
14031413 ## Examples
14041414
1405- iex> Calendar.ISO.naive_datetime_to_iodata(2015, 2, 28, 1, 2, 3, {4, 6}, :basic)
1406- [["2015", ["0", "2"], "28"], 32, [[["0", "1"], ["0", "2"], ["0", "3"]], 46, ["00000", "4"]]]
1415+ iex> data = Calendar.ISO.naive_datetime_to_iodata(2015, 2, 28, 1, 2, 3, {4, 6}, :basic)
1416+ iex> IO.iodata_to_binary(data)
1417+ "20150228 010203.000004"
1418+
1419+ iex> data = Calendar.ISO.naive_datetime_to_iodata(2015, 2, 28, 1, 2, 3, {4, 6}, :extended)
1420+ iex> IO.iodata_to_binary(data)
1421+ "2015-02-28 01:02:03.000004"
14071422
14081423 """
14091424 @ doc since: "1.19.0"
1425+ @ spec naive_datetime_to_string (
1426+ year ,
1427+ month ,
1428+ day ,
1429+ Calendar . hour ( ) ,
1430+ Calendar . minute ( ) ,
1431+ Calendar . second ( ) ,
1432+ Calendar . microsecond ( ) ,
1433+ :basic | :extended
1434+ ) :: iodata
14101435 def naive_datetime_to_iodata (
14111436 year ,
14121437 month ,
@@ -1419,8 +1444,8 @@ defmodule Calendar.ISO do
14191444 ) do
14201445 [
14211446 date_to_iodata ( year , month , day , format ) ,
1422- ?\s ,
1423- time_to_iodata ( hour , minute , second , microsecond , format )
1447+ ?\s
1448+ | time_to_iodata ( hour , minute , second , microsecond , format )
14241449 ]
14251450 end
14261451
@@ -1512,11 +1537,26 @@ defmodule Calendar.ISO do
15121537 ## Examples
15131538
15141539 iex> time_zone = "Etc/UTC"
1515- iex> Calendar.ISO.datetime_to_iodata(2017, 8, 1, 1, 2, 3, {4, 5}, time_zone, "UTC", 0, 0)
1516- [["2017", 45, ["0", "8"], 45, ["0", "1"]], 32, [[["0", "1"], 58, ["0", "2"], 58, ["0", "3"]], 46, ["0000", "0"]], 90, []]
1540+ iex> data = Calendar.ISO.datetime_to_iodata(2017, 8, 1, 1, 2, 3, {4, 5}, time_zone, "UTC", 0, 0)
1541+ iex> IO.iodata_to_binary(data)
1542+ "2017-08-01 01:02:03.00000Z"
15171543
15181544 """
15191545 @ doc since: "1.19.0"
1546+ @ spec datetime_to_iodata (
1547+ year ,
1548+ month ,
1549+ day ,
1550+ Calendar . hour ( ) ,
1551+ Calendar . minute ( ) ,
1552+ Calendar . second ( ) ,
1553+ Calendar . microsecond ( ) ,
1554+ Calendar . time_zone ( ) ,
1555+ Calendar . zone_abbr ( ) ,
1556+ Calendar . utc_offset ( ) ,
1557+ Calendar . std_offset ( ) ,
1558+ :basic | :extended
1559+ ) :: iodata
15201560 def datetime_to_iodata (
15211561 year ,
15221562 month ,
@@ -1562,15 +1602,15 @@ defmodule Calendar.ISO do
15621602 end
15631603
15641604 defp format_offset ( total , hour , minute , :extended ) do
1565- [ sign ( total ) , zero_pad ( hour , 2 ) , ?: , zero_pad ( minute , 2 ) ]
1605+ [ sign ( total ) , zero_pad ( hour , 2 ) , ?: | zero_pad ( minute , 2 ) ]
15661606 end
15671607
15681608 defp format_offset ( total , hour , minute , :basic ) do
1569- [ sign ( total ) , zero_pad ( hour , 2 ) , zero_pad ( minute , 2 ) ]
1609+ [ sign ( total ) , zero_pad ( hour , 2 ) | zero_pad ( minute , 2 ) ]
15701610 end
15711611
15721612 defp zone_to_iodata ( _ , _ , _ , "Etc/UTC" ) , do: [ ]
1573- defp zone_to_iodata ( _ , _ , abbr , zone ) , do: [ ?\s , abbr , ?\s , zone ]
1613+ defp zone_to_iodata ( _ , _ , abbr , zone ) , do: [ ?\s , abbr , ?\s | zone ]
15741614
15751615 @ doc """
15761616 Determines if the date given is valid according to the proleptic Gregorian calendar.
@@ -1639,16 +1679,16 @@ defmodule Calendar.ISO do
16391679
16401680 case max ( count - byte_size ( num ) , 0 ) do
16411681 0 -> num
1642- 1 -> [ "0" , num ]
1643- 2 -> [ "00" , num ]
1644- 3 -> [ "000" , num ]
1645- 4 -> [ "0000" , num ]
1646- 5 -> [ "00000" , num ]
1682+ 1 -> [ "0" | num ]
1683+ 2 -> [ "00" | num ]
1684+ 3 -> [ "000" | num ]
1685+ 4 -> [ "0000" | num ]
1686+ 5 -> [ "00000" | num ]
16471687 end
16481688 end
16491689
16501690 defp zero_pad ( val , count ) do
1651- [ ?- , zero_pad ( - val , count ) ]
1691+ [ ?- | zero_pad ( - val , count ) ]
16521692 end
16531693
16541694 @ doc """
0 commit comments