@@ -13,7 +13,7 @@ public enum UTC {
1313}
1414
1515extension UTC {
16- /// Date and time using the UTC calendar and timezone as `DateFormatter` base .
16+ /// Date and time using the UTC calendar and timezone.
1717 /// - Example: `2019-09-09 11:43:09`
1818 internal final class Timestamp {
1919 private var _components = DateComponents ( )
@@ -54,17 +54,34 @@ extension UTC {
5454
5555 var result = String ( )
5656 result. reserveCapacity ( 19 )
57+
5758 result. append ( String ( components. year!) )
5859 result. append ( " - " )
59- result. append ( String ( components. month!) )
60+
61+ let month = components. month!
62+ if month < 10 { result. append ( " 0 " ) }
63+ result. append ( String ( month) )
6064 result. append ( " - " )
61- result. append ( String ( components. day!) )
65+
66+ let day = components. day!
67+ if day < 10 { result. append ( " 0 " ) }
68+ result. append ( String ( day) )
6269 result. append ( " " )
63- result. append ( String ( components. hour!) )
70+
71+ let hour = components. hour!
72+ if hour < 10 { result. append ( " 0 " ) }
73+ result. append ( String ( hour) )
6474 result. append ( " : " )
65- result. append ( String ( components. minute!) )
75+
76+ let minute = components. minute!
77+ if minute < 10 { result. append ( " 0 " ) }
78+ result. append ( String ( minute) )
6679 result. append ( " : " )
67- result. append ( String ( components. second!) )
80+
81+ let second = components. second!
82+ if second < 10 { result. append ( " 0 " ) }
83+ result. append ( String ( second) )
84+
6885 return result
6986 }
7087 }
0 commit comments