@@ -155,25 +155,43 @@ pub fn to_naive_date_string(value: Time) -> String {
155155pub fn to_time_string ( value : Time ) -> String {
156156 let # ( _ , # ( hour , minute , second , milli_second ) , offset ) = to_parts ( value )
157157 pad2 ( hour )
158- <> ":" <> pad2 ( minute )
159- <> ":" <> pad2 ( second )
160- <> "." <> pad3 ( milli_second )
158+ <> ":"
159+ <> pad2 ( minute )
160+ <> ":"
161+ <> pad2 ( second )
162+ <> "."
163+ <> pad3 ( milli_second )
161164 <> offset
162165}
163166
164167/// like `to_time_string` except it does not contain the offset
165168pub fn to_naive_time_string ( value : Time ) -> String {
166169 let # ( _ , # ( hour , minute , second , milli_second ) , _ ) = to_parts ( value )
167- pad2 ( hour ) <> ":" <> pad2 ( minute ) <> ":" <> pad2 ( second ) <> "." <> pad3 ( milli_second )
170+ pad2 ( hour )
171+ <> ":"
172+ <> pad2 ( minute )
173+ <> ":"
174+ <> pad2 ( second )
175+ <> "."
176+ <> pad3 ( milli_second )
168177}
169178
170179pub fn to_iso8601 ( value : Time ) -> String {
171180 let # ( # ( year , month , day ) , # ( hour , minute , second , milli_second ) , offset ) =
172181 to_parts ( value )
173- int . to_string ( year ) <> "-" <> pad2 ( month ) <> "-" <> pad2 ( day )
182+ int . to_string ( year )
183+ <> "-"
184+ <> pad2 ( month )
185+ <> "-"
186+ <> pad2 ( day )
174187 <> "T"
175- <> pad2 ( hour ) <> ":" <> pad2 ( minute ) <> ":" <> pad2 ( second )
176- <> "." <> pad3 ( milli_second )
188+ <> pad2 ( hour )
189+ <> ":"
190+ <> pad2 ( minute )
191+ <> ":"
192+ <> pad2 ( second )
193+ <> "."
194+ <> pad3 ( milli_second )
177195 <> offset
178196}
179197
@@ -433,9 +451,12 @@ pub fn parse_naive_time_of_day(
433451
434452pub fn time_of_day_to_string ( value : TimeOfDay ) -> String {
435453 int . to_string ( value . hour )
436- <> ":" <> pad2 ( value . minute )
437- <> ":" <> pad2 ( value . second )
438- <> "." <> pad3 ( value . nanosecond / 1_000_000 )
454+ <> ":"
455+ <> pad2 ( value . minute )
456+ <> ":"
457+ <> pad2 ( value . second )
458+ <> "."
459+ <> pad3 ( value . nanosecond / 1_000_000 )
439460}
440461
441462pub fn time_of_day_to_short_string ( value : TimeOfDay ) -> String {
@@ -446,10 +467,19 @@ pub fn time_of_day_to_short_string(value: TimeOfDay) -> String {
446467pub fn to_naive ( value : Time ) -> String {
447468 let # ( # ( year , month , day ) , # ( hour , minute , second , milli_second ) , _ ) =
448469 to_parts ( value )
449- int . to_string ( year ) <> "-" <> pad2 ( month ) <> "-" <> pad2 ( day )
470+ int . to_string ( year )
471+ <> "-"
472+ <> pad2 ( month )
473+ <> "-"
474+ <> pad2 ( day )
450475 <> "T"
451- <> pad2 ( hour ) <> ":" <> pad2 ( minute ) <> ":" <> pad2 ( second )
452- <> "." <> pad3 ( milli_second )
476+ <> pad2 ( hour )
477+ <> ":"
478+ <> pad2 ( minute )
479+ <> ":"
480+ <> pad2 ( second )
481+ <> "."
482+ <> pad3 ( milli_second )
453483}
454484
455485/// accepts fromats similar to the ones listed for `parse` except that there shoundn't be any offset information
@@ -518,10 +548,18 @@ pub fn to_http(value: Time) -> String {
518548 let assert Ok ( value ) = set_offset ( value , "Z" )
519549 let # ( # ( year , _ , day ) , # ( hour , minute , second , _ ) , _ ) = to_parts ( value )
520550 short_string_weekday ( value )
521- <> ", " <> pad2 ( day )
522- <> " " <> short_string_month ( value )
523- <> " " <> int . to_string ( year )
524- <> " " <> pad2 ( hour ) <> ":" <> pad2 ( minute ) <> ":" <> pad2 ( second )
551+ <> ", "
552+ <> pad2 ( day )
553+ <> " "
554+ <> short_string_month ( value )
555+ <> " "
556+ <> int . to_string ( year )
557+ <> " "
558+ <> pad2 ( hour )
559+ <> ":"
560+ <> pad2 ( minute )
561+ <> ":"
562+ <> pad2 ( second )
525563 <> " GMT"
526564}
527565
@@ -535,11 +573,20 @@ pub fn to_http_with_offset(value: Time) -> String {
535573 }
536574
537575 short_string_weekday ( value )
538- <> ", " <> pad2 ( day )
539- <> " " <> short_string_month ( value )
540- <> " " <> int . to_string ( year )
541- <> " " <> pad2 ( hour ) <> ":" <> pad2 ( minute ) <> ":" <> pad2 ( second )
542- <> " " <> offset
576+ <> ", "
577+ <> pad2 ( day )
578+ <> " "
579+ <> short_string_month ( value )
580+ <> " "
581+ <> int . to_string ( year )
582+ <> " "
583+ <> pad2 ( hour )
584+ <> ":"
585+ <> pad2 ( minute )
586+ <> ":"
587+ <> pad2 ( second )
588+ <> " "
589+ <> offset
543590}
544591
545592/// see [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date)
@@ -1020,7 +1067,12 @@ pub fn range(from a: Time, to b: option.Option(Time), step s: duration.Duration)
10201067pub fn set_timezone ( value : Time , new_timezone : String ) -> Result ( Time , Nil ) {
10211068 use new_offset_seconds <- result . try ( list . key_find ( zones . list , new_timezone ) )
10221069 let Time ( timestamp : ts , monotonic_time : mt , .. ) = value
1023- Time ( ts , time_duration . seconds ( new_offset_seconds ) , option . Some ( new_timezone ) , mt )
1070+ Time (
1071+ ts ,
1072+ time_duration . seconds ( new_offset_seconds ) ,
1073+ option . Some ( new_timezone ) ,
1074+ mt ,
1075+ )
10241076 |> Ok
10251077}
10261078
@@ -1123,12 +1175,7 @@ pub fn from_erlang_local_datetime(
11231175 |> set_day ( Day ( date . 0 , date . 1 , date . 2 ) )
11241176 |> set_time_of_day ( TimeOfDay ( time . 0 , time . 1 , time . 2 , 0 ) )
11251177
1126- Time (
1127- base . timestamp ,
1128- offset ,
1129- validate_timezone ( local_timezone ( ) ) ,
1130- option . None ,
1131- )
1178+ Time ( base . timestamp , offset , validate_timezone ( local_timezone ( ) ) , option . None )
11321179}
11331180
11341181@ target ( erlang )
@@ -1278,7 +1325,9 @@ fn generate_offset(offset: time_duration.Duration) -> Result(String, Nil) {
12781325 False -> "+"
12791326 }
12801327
1281- Ok ( sign <> pad2 ( abs_seconds / 3600 ) <> ":" <> pad2 ( { abs_seconds % 3600 } / 60 ) )
1328+ Ok (
1329+ sign <> pad2 ( abs_seconds / 3600 ) <> ":" <> pad2 ( { abs_seconds % 3600 } / 60 ) ,
1330+ )
12821331}
12831332
12841333fn parse_date_section ( date : String ) -> Result ( List ( Int ) , Nil ) {
0 commit comments