Skip to content

Commit 0192f39

Browse files
committed
Tweak on DateFormatters
1 parent c412e48 commit 0192f39

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

IG/IG.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@
797797
children = (
798798
8DC4CA492149A6CE00344CBF /* Date.swift */,
799799
8D9FB786231F943C00D76B6A /* DateFormatter.swift */,
800+
8D88F5F8246C79D900743B2B /* UTC.swift */,
800801
8D911F6422ECF4CA0038E899 /* Decimal.swift */,
801802
8D3C262422E9FA020080D3C1 /* Collections.swift */,
802803
8D569217245FE63D00E9E621 /* c */,
@@ -806,7 +807,6 @@
806807
8DF85B1B22F046FA00F1C525 /* Error.swift */,
807808
8D19C51A2326459000F029B3 /* ErrorHelper.swift */,
808809
8D30D082232566D900D83E0A /* ErrorCodable.swift */,
809-
8D88F5F8246C79D900743B2B /* UTC.swift */,
810810
);
811811
path = utils;
812812
sourceTree = "<group>";

IG/sources/utils/Decimal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extension Decimal {
6767
///
6868
/// The operation is: `Decimal(value) / (10^power)`
6969
/// - precondition: `power` must be zero or a positive number.
70-
internal init<I>(_ value: I, divingByPowerOf10 power: Int) where I:BinaryInteger {
70+
@inlinable internal init<I>(_ value: I, divingByPowerOf10 power: Int) where I:BinaryInteger {
7171
precondition(power > 0)
7272
let lhs: Decimal = Decimal(exactly: value)!
7373
let rhs: Decimal = pow(10 as Decimal, power)

IG/sources/utils/UTC.swift

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public enum UTC {
1313
}
1414

1515
extension 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

Comments
 (0)