@@ -1107,8 +1107,11 @@ defmodule DateTime do
11071107 std_offset: std_offset
11081108 } = datetime
11091109
1110- datetime_to_string ( year , month , day , hour , minute , second , microsecond , format ) <>
1111- Calendar.ISO . offset_to_string ( utc_offset , std_offset , time_zone , format )
1110+ [
1111+ datetime_to_iodata ( year , month , day , hour , minute , second , microsecond , format ) ,
1112+ Calendar.ISO . offset_to_iodata ( utc_offset , std_offset , time_zone , format )
1113+ ]
1114+ |> IO . iodata_to_binary ( )
11121115 end
11131116
11141117 def to_iso8601 (
@@ -1119,17 +1122,41 @@ defmodule DateTime do
11191122 when format in [ :extended , :basic ] do
11201123 { year , month , day , hour , minute , second , { microsecond , _ } } = shift_by_offset ( datetime , 0 )
11211124
1122- datetime_to_string ( year , month , day , hour , minute , second , { microsecond , precision } , format ) <>
1123- "Z"
1125+ [
1126+ datetime_to_iodata (
1127+ year ,
1128+ month ,
1129+ day ,
1130+ hour ,
1131+ minute ,
1132+ second ,
1133+ { microsecond , precision } ,
1134+ format
1135+ ) ,
1136+ ?Z
1137+ ]
1138+ |> IO . iodata_to_binary ( )
11241139 end
11251140
11261141 def to_iso8601 ( % { calendar: Calendar.ISO } = datetime , format , offset )
11271142 when format in [ :extended , :basic ] do
11281143 { _ , precision } = datetime . microsecond
11291144 { year , month , day , hour , minute , second , { microsecond , _ } } = shift_by_offset ( datetime , offset )
11301145
1131- datetime_to_string ( year , month , day , hour , minute , second , { microsecond , precision } , format ) <>
1132- Calendar.ISO . offset_to_string ( offset , 0 , nil , format )
1146+ [
1147+ datetime_to_iodata (
1148+ year ,
1149+ month ,
1150+ day ,
1151+ hour ,
1152+ minute ,
1153+ second ,
1154+ { microsecond , precision } ,
1155+ format
1156+ ) ,
1157+ Calendar.ISO . offset_to_iodata ( offset , 0 , nil , format )
1158+ ]
1159+ |> IO . iodata_to_binary ( )
11331160 end
11341161
11351162 def to_iso8601 ( % { calendar: _ } = datetime , format , offset ) when format in [ :extended , :basic ] do
@@ -1148,10 +1175,12 @@ defmodule DateTime do
11481175 |> calendar . naive_datetime_from_iso_days ( )
11491176 end
11501177
1151- defp datetime_to_string ( year , month , day , hour , minute , second , microsecond , format ) do
1152- Calendar.ISO . date_to_string ( year , month , day , format ) <>
1153- "T" <>
1154- Calendar.ISO . time_to_string ( hour , minute , second , microsecond , format )
1178+ defp datetime_to_iodata ( year , month , day , hour , minute , second , microsecond , format ) do
1179+ [
1180+ Calendar.ISO . date_to_iodata ( year , month , day , format ) ,
1181+ "T" ,
1182+ Calendar.ISO . time_to_iodata ( hour , minute , second , microsecond , format )
1183+ ]
11551184 end
11561185
11571186 @ doc """
0 commit comments