From b2fca066c25c2e48cade909c214a2e2e1f6d0808 Mon Sep 17 00:00:00 2001 From: Ralph Kuepper Date: Mon, 18 Jan 2021 12:18:43 +0100 Subject: [PATCH] fixed a few problems and added a new case --- .swiftformat | 13 + .../UserInterfaceState.xcuserstate | Bin 21217 -> 26993 bytes Sources/String+SwiftyDates.swift | 156 ++++++----- SwiftyDatesTests/SwiftyDatesTests.swift | 251 +++++++++--------- 4 files changed, 233 insertions(+), 187 deletions(-) create mode 100644 .swiftformat diff --git a/.swiftformat b/.swiftformat new file mode 100644 index 0000000..52322f8 --- /dev/null +++ b/.swiftformat @@ -0,0 +1,13 @@ +# file options + +--swiftversion 5.2 +--exclude .build + +# format options + +--self insert +--patternlet inline +--stripunusedargs unnamed-only +--ifdef no-indent + +# rules diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/amlug.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/amlug.xcuserdatad/UserInterfaceState.xcuserstate index 167ae2f816c186cc5a9b91b449fa3ea75aae19d8..e76bd0a02a0afdcdc94b89ccc3e90aedf3f0f8d4 100644 GIT binary patch delta 15314 zcma)D30%|V|9_tErO2@j1_EPjY#d{3Y-1b8U@#b{cp!3k0E!4xrwGX5k=dTFnU!Xi zE3Y&KJbrfAVP<7n*`-OkX@_R!(P5VP|9m%4t6#r=@Y;C3-{<-~pXdF&pU>xc zK76qOUpj~%s>4?wo}l)OLZi_bRE4Th4H}Eap;|N^)u9Qf9d)1?XeOG4W}`dM9CRmI zfbK>2q5IK7^dNcyJ&B$|Popj98T2fA4n2>yq8HFM^dj1hUO_w2o9J!y4mymEprhy* z`UD+EpQ01!9QqEON8h6h=m+#8`U(Ave)XX1xDW1&MK~Ns;Qm;K6tG!~=0L9*j%z2waIr;%Yn%H{oX7f~VtF+=kon9e57r@jUzhUW^~a zOYo!kG2Dqa;s4+*_<6hwzlGn%@8Eaw2lzvL2zx%pC-6!989s%-!r$Rb_%i+pU&nvo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ULu!+O~IuJwrZnDw~zob`hB2kVd4%hq44*Q~!=|Fqt)-inWoPm3QNPvbYozZ3tX zE!^g?rP{jNdf9s0a%_Wa#kNx05ZiFuNZV-J7+aNXf^C{@w%_Kr&9yDCEwnAREww#q zYqM>#?XvB)y=>cWJ7jyqcG&ig?Ni%#wu`n)w#&9(ZP#so+Wxk8wujlpcA0&oz1BX{ zKF7}4AG9y9FS0MOFSqmdRrYQ6XYD)eJMFvdd+dAdFWXmz@%)#;J40I1Nsl-|2RyI=ef2Ir})%of*z7=K$w0 z=L60PXO(lDv(8!XY;ewYQs)xqqt2Di)y{R!_0CpjyK|TGfb(_dTh4c!?>mn=zi^&+ zUUPMFg}Edyxhuk@ap_z!u2`4Z)y>t@mFDW>>gURG<+?ns0j@!=BG+(Njcc}RxoeBd zzu)zd>tYg0k|wE=dL?BfWhNCTJ&;tBG%jg;(!?ZR($u6GNwbsuNxPDcCVijubJAZ) zH&|dzyYt*0_h5IKdyIRc+vlF@p5dPD ze$c(Zy~w@9z0AGF{giuaep&vI{ObIs{FeMF`P1`f<@@vJ<}b^CG=F9O>ioy^*X6Iz z-;n=S{tq6NC*70pDe?^SjP%raCU}}W4|*Q*Eb~0-S?O8jY4>dQZ1p_j+2Psg>G85> nzvng2LC?FM_dG{DpLkAt&Un7@d>iz85emM^<@?=X&$<5th#(GQ diff --git a/Sources/String+SwiftyDates.swift b/Sources/String+SwiftyDates.swift index 0ba13f0..309ff2e 100644 --- a/Sources/String+SwiftyDates.swift +++ b/Sources/String+SwiftyDates.swift @@ -17,100 +17,106 @@ extension String { var cleanedTime = self.replacingOccurrences(of: "[a-zA-Z]", with: "", options: .regularExpression).replacingOccurrences(of: " ", with: "") let sep: Character = (self.contains(".") && !self.contains(":")) ? "." : ":" - if (self.contains("-") || self.contains("+")) { + if self.contains("-") || self.contains("+") { let sign: Double = self.contains("-") ? -1 : 1 - + let timeParts = split(separator: sign == 1 ? "+" : "-").map(String.init) cleanedTime = timeParts[0] - if (timeParts[1].contains(":")) { + if timeParts[1].contains(":") { let intervalParts = timeParts[1].split(separator: ":").compactMap(Double.init) - offset = sign * (intervalParts[0]*3600 + intervalParts[1]*60) - if (intervalParts.count > 2) { + offset = sign * (intervalParts[0] * 3600 + intervalParts[1] * 60) + if intervalParts.count > 2 { offset = offset + intervalParts[2] } } else { - offset = (Double(timeParts[1]) ?? 0) * sign + if timeParts[1].count == 4 { + let s = String(timeParts[1]) + let h = Double(s.prefix(2)) ?? 0 + let m = Double(s.suffix(2)) ?? 0 + offset = (h * 60 + m) * 60 + } else { + offset = (Double(timeParts[1]) ?? 0) * 60 * sign + } } } + cleanedTime = cleanedTime.replacingOccurrences(of: " ", with: "") let parts = cleanedTime.split(separator: sep).compactMap(Double.init) - if (parts.count > 0) { + if parts.count > 0 { hour = parts[0] } - if (parts.count > 1) { + if parts.count > 1 { minute = parts[1] } - if (parts.count > 2) { + if parts.count > 2 { second = parts[2] } - if (self.contains("pm")) { + if self.contains("pm") { hour = hour + 12 } return Double((hour * 3600) + (minute * 60) + second - offset) } - - public func swiftyDate(calendar:Calendar = Calendar.current) -> Date? { + + public func swiftyDate(calendar: Calendar = Calendar.current) -> Date? { // is this even a string we can work with? - if (self.count < 1) { return nil } - + if self.count < 1 { return nil } + var day: Int? var month: Int? var year: Int? - + // check for german dates ((d)d.(m)m.(yy)yy) or ((m)m.(yy)yy) or ((d)d.(m)m) - if (contains(".")) { // most obvious sign for a german date - let parts = split(separator: ".").map { Int($0) ?? 0} - if (parts.count == 3) { + if contains(".") { // most obvious sign for a german date + let parts = split(separator: ".").map { Int($0) ?? 0 } + if parts.count == 3 { day = parts[0] month = parts[1] year = parts.last! - } else if (parts.count == 2) { + } else if parts.count == 2 { // checking if the later number is a year (>12 or 4-digits) - if (parts.last! > 12) { + if parts.last! > 12 { year = parts.last! month = parts[0] - } - else { + } else { month = parts.last! day = parts[0] } } - } else if (contains("-") || contains("/")) { + } else if contains("-") || contains("/") { let sep: Character = self.contains("/") ? "/" : "-" - let usWay = sep == "/" let parts = split(separator: sep).map { Int($0) ?? 0 } - let isoOrder = parts[0] > 12 && parts[1] < 13 - if (parts.count == 3) { + let usWay = parts[1] > 12 + let isoOrder = parts[0] > 1000 && parts[1] < 13 + if parts.count == 3 { let reverseIsoOrder = !usWay && parts[2] > 12 && parts[1] < 13 - if (isoOrder) { + if isoOrder { year = parts[0] month = parts[1] day = parts[2] - } else if (reverseIsoOrder) { + } else if reverseIsoOrder { year = parts[2] month = parts[1] day = parts[0] } else { - if (usWay) { + if usWay { day = parts[1] month = parts[0] - } - else { + } else { day = parts[0] month = parts[1] } year = parts.last! } - } else if (parts.count == 2) { - if (isoOrder) { + } else if parts.count == 2 { + if isoOrder { year = parts[0] month = parts[1] } else { // checking if the later number is a year (>12 or 4-digits) - if (parts.last! > 12) { + if parts.last! > 12 { year = parts.last! month = parts[0] } else { - if (usWay) { + if usWay { day = parts.last! month = parts[0] } else { @@ -119,12 +125,10 @@ extension String { } } } - } } else { let intValue = Int(self) ?? 0 - print("int value is: ", intValue) - if (self.count == 4 || intValue > 12) { + if self.count == 4 || intValue > 12 { year = intValue } else { month = intValue @@ -132,50 +136,82 @@ extension String { } // if no year is given we use the current year let date = Date() - if (year == nil) { + if year == nil { year = calendar.component(.year, from: date) } - if (year! < 50) { + if year! < 50 { year = 2000 + year! } - + if year! > 5000 { if let timestamp = TimeInterval(self) { return Date(timeIntervalSince1970: timestamp) } } - - let components = DateComponents(calendar: calendar, year: year, month: month, day: day) + + let components = DateComponents(calendar: calendar, year: year, month: month, day: day, hour: 0, minute: 0, second: 0) return components.date } + public func swiftyDateTime(calendar: Calendar = Calendar.current, baseDate: Date = Date()) -> Date? { - if (self == "") { return nil } - + if self == "" { return nil } + var time: TimeInterval = 0 var date: Date? - + // cleaning let cleanString = replacingOccurrences(of: " am", with: "am").replacingOccurrences(of: " pm", with: "pm") - + // check for iso 8601 (yyyy-MM-ddTHH:mm:ss.SSZ) - if (cleanString.contains("T")) { - let parts:[String] = split(separator: "T").map(String.init) - date = parts[0].swiftyDate() + if cleanString.contains("T") { + let parts: [String] = split(separator: "T").map(String.init) + date = parts[0].swiftyDate(calendar: calendar) time = parts[1].swiftyTime() - } else if (cleanString.contains(" ") && (cleanString.contains(":") || cleanString.contains("am") || cleanString.contains("pm")) && (cleanString.contains("/") || cleanString.contains("-") || cleanString.contains("."))) { - if let pos = index(of: " ") { - date = String(self[.. 1 { + // we likely have Fri, 15 Jan 2021 13:22:00 -0500 date + let cleanString_ = cleanString.lowercased() + .replacingOccurrences(of: " jan ", with: "/01/") + .replacingOccurrences(of: " feb ", with: "/02/") + .replacingOccurrences(of: " mar ", with: "/03/") + .replacingOccurrences(of: " apr ", with: "/04/") + .replacingOccurrences(of: " may ", with: "/05/") + .replacingOccurrences(of: " jun ", with: "/06/") + .replacingOccurrences(of: " jul ", with: "/07/") + .replacingOccurrences(of: " aug ", with: "/08/") + .replacingOccurrences(of: " sep ", with: "/09/") + .replacingOccurrences(of: " oct ", with: "/10/") + .replacingOccurrences(of: " nov ", with: "/11/") + .replacingOccurrences(of: " dec ", with: "/12/") + .replacingOccurrences(of: "mon, ", with: "") + .replacingOccurrences(of: "tue, ", with: "") + .replacingOccurrences(of: "wed, ", with: "") + .replacingOccurrences(of: "thu, ", with: "") + .replacingOccurrences(of: "fri, ", with: "") + .replacingOccurrences(of: "sat, ", with: "") + .replacingOccurrences(of: "sun, ", with: "") + print("new me: ", cleanString_) + if let pos = cleanString_.index(of: " ") { + date = String(cleanString_[.. DateFormatter { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "MM/dd/yyyy HH:mm:ss" dateFormatter.timeZone = TimeZone(identifier: "America/New_York") return dateFormatter } - + func testIsoCases() { - let dateFormatter = getDateFormatter() - for tc in iso8601TestCases { - let date:Date? = tc.input.swiftyDateTime() - if (date == nil) { + let dateFormatter = self.getDateFormatter() + for tc in self.iso8601TestCases { + let date: Date? = tc.input.swiftyDateTime() + if date == nil { XCTAssertNil(tc.output) - } - else { - let formatedDate = dateFormatter.string(from: date!) + } else { + let formatedDate = dateFormatter.string(from: date!.addingTimeInterval(60 * 60 * 6)) XCTAssertEqual(formatedDate, tc.output) } - } } - + func testDateCases() { - let dateFormatter = getDateFormatter() - for tc in dateTestCases { - let date:Date? = tc.input.swiftyDateTime() - if (date == nil) { + let dateFormatter = self.getDateFormatter() + for tc in self.dateTestCases { + let date: Date? = tc.input.swiftyDate() + if date == nil { XCTAssertNil(tc.output) - } - else { - let formatedDate = dateFormatter.string(from: date!) + } else { + let formatedDate = dateFormatter.string(from: date!.addingTimeInterval(60 * 60 * 6)) XCTAssertEqual(formatedDate, tc.output) } } } - + func testDateTimeCases() { - let dateFormatter = getDateFormatter() - for tc in datetimeTestCases { - let date:Date? = tc.input.swiftyDateTime() - if (date == nil) { + let dateFormatter = self.getDateFormatter() + for tc in self.datetimeTestCases { + let date: Date? = tc.input.swiftyDateTime() + if date == nil { XCTAssertNil(tc.output) - } - else { - let formatedDate = dateFormatter.string(from: date!) + } else { + let formatedDate = dateFormatter.string(from: date!.addingTimeInterval(60 * 60 * 6)) XCTAssertEqual(formatedDate, tc.output) } } } - + func testTimeCases() { - let dateFormatter = getDateFormatter() - let testDate:Date = DateComponents(calendar: Calendar.current, year: 2018, month: 1, day: 1).date! - - - for tc in timeTestCases { - //print("Parsing: ", tc.input, tc.output) - let date:Date? = tc.input.swiftyDateTime(calendar: Calendar.current, baseDate: testDate) - //print("we got: ",dateFormatter.string(from: date!)) - if (date == nil) { + let dateFormatter = self.getDateFormatter() + let testDate: Date = DateComponents(calendar: Calendar.current, year: 2018, month: 1, day: 1).date! + + for tc in self.timeTestCases { + // print("Parsing: ", tc.input, tc.output) + let date: Date? = tc.input.swiftyDateTime(calendar: Calendar.current, baseDate: testDate) + // print("we got: ",dateFormatter.string(from: date!)) + if date == nil { XCTAssertNil(tc.output) - } - else { - let formatedDate = dateFormatter.string(from: date!) + } else { + let formatedDate = dateFormatter.string(from: date!.addingTimeInterval(60 * 60 * 6)) XCTAssertEqual(formatedDate, tc.output) } } } - + func testDateTimePerformanceExample() { // This is an example of a performance test case. self.measure { _ = "2018-03-08T15:49:46+00:00".swiftyDateTime() } } - + func testManualPerformance() { let startTime = CFAbsoluteTimeGetCurrent() let cycles = 10000 let dateString = "2018-03-08T15:49:46" - - for _ in 1...cycles { + + for _ in 1 ... cycles { _ = dateString.swiftyDateTime() } let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime print("Time elapsed for \(cycles) cycles: \(timeElapsed) s.") - let perCall = timeElapsed/Double(cycles) + let perCall = timeElapsed / Double(cycles) print("That is: \(perCall) s for one swiftyDateTime() call.") - + print("Comparing that to the DateFormatter...") let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss" formatter.calendar = Calendar(identifier: .iso8601) formatter.timeZone = TimeZone(secondsFromGMT: 0) formatter.locale = Locale(identifier: "en_US_POSIX") - + let startTime2 = CFAbsoluteTimeGetCurrent() - for _ in 1...cycles { + for _ in 1 ... cycles { formatter.date(from: dateString) } let timeElapsed2 = CFAbsoluteTimeGetCurrent() - startTime2 print("Time elapsed for \(cycles) cycles: \(timeElapsed2) s.") - let perCall2 = timeElapsed2/Double(cycles) + let perCall2 = timeElapsed2 / Double(cycles) print("That is: \(perCall2) s for one DateFormatter() call.") - let faster = perCall-perCall2 + let faster = perCall - perCall2 print("DateFormatter is \(faster) fast than SwiftyDates.") - } - + func testTimePerformance() { self.measure { _ = "2018-03-08".swiftyDate() } } - }