From 48004ad0158fd3925ceb677d937024131dda412c Mon Sep 17 00:00:00 2001 From: Martynas Limontas Date: Mon, 1 Feb 2021 12:02:42 +0200 Subject: [PATCH 1/7] test background (in progress) --- .../RRuleExampleViewController.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/RRuleSwiftExample/RRuleExampleViewController.swift b/RRuleSwiftExample/RRuleExampleViewController.swift index 7a26e74..2fd45e7 100644 --- a/RRuleSwiftExample/RRuleExampleViewController.swift +++ b/RRuleSwiftExample/RRuleExampleViewController.swift @@ -61,6 +61,7 @@ class RRuleExampleViewController: UIViewController { super.viewDidLoad() setupUI() testRRuleIterator() + testRRuleIteratorMultipleThreads() } fileprivate func setupUI() { @@ -72,7 +73,26 @@ class RRuleExampleViewController: UIViewController { textView.delegate = self navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Reset", style: .plain, target: self, action: #selector(resetButtonTapped(_:))) } + + fileprivate func testRRuleIteratorMultipleThreads() { + DispatchQueue.global(qos: .background).async { + for n in 1...1000 + { + self.testRRuleIterator(n) + } + } + DispatchQueue.global(qos: .background).async { + for n in 1...1000 + { + self.testRRuleIterator(-n) + } + } + } + + fileprivate func testRRuleIterator(_ n : Int) { + } + fileprivate func testRRuleIterator() { let dateFormatter: DateFormatter = { let dateFormatter = DateFormatter() From 091a65c2831df5ba095a79ccca7a6a8b9066aeef Mon Sep 17 00:00:00 2001 From: Martynas Limontas Date: Mon, 1 Feb 2021 13:14:52 +0200 Subject: [PATCH 2/7] reduced JSContext evaluateScript calls, multiple threads test --- .../RRuleExampleViewController.swift | 39 +++++++++++++++++-- Sources/Iterators.swift | 6 +-- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/RRuleSwiftExample/RRuleExampleViewController.swift b/RRuleSwiftExample/RRuleExampleViewController.swift index 2fd45e7..feaca31 100644 --- a/RRuleSwiftExample/RRuleExampleViewController.swift +++ b/RRuleSwiftExample/RRuleExampleViewController.swift @@ -61,7 +61,6 @@ class RRuleExampleViewController: UIViewController { super.viewDidLoad() setupUI() testRRuleIterator() - testRRuleIteratorMultipleThreads() } fileprivate func setupUI() { @@ -76,14 +75,14 @@ class RRuleExampleViewController: UIViewController { fileprivate func testRRuleIteratorMultipleThreads() { DispatchQueue.global(qos: .background).async { - for n in 1...1000 + for n in 1...100 { self.testRRuleIterator(n) } } DispatchQueue.global(qos: .background).async { - for n in 1...1000 + for n in 1...100 { self.testRRuleIterator(-n) } @@ -91,6 +90,40 @@ class RRuleExampleViewController: UIViewController { } fileprivate func testRRuleIterator(_ n : Int) { + let ruleFormat = "RRULE:FREQ=WEEKLY;DTSTART=%@%@01T014500Z;INTERVAL=1;UNTIL=%@%@01T014500Z" + let calendar = NSCalendar.current + var startDateComponents = DateComponents() + startDateComponents.month = n; + let startDate = calendar.date(byAdding: startDateComponents, to: Date()) + startDateComponents = calendar.dateComponents([.year, .month], from: startDate!) + + var endDateComponents = DateComponents() + endDateComponents.month = 6 + let endDate = calendar.date(byAdding: endDateComponents, to: startDate!) + endDateComponents = calendar.dateComponents([.year, .month], from: endDate!) + + var startDateMonth = String(startDateComponents.month!) + if (startDateComponents.month! < 10) + { + startDateMonth = "0".appending(startDateMonth) + } + var endDateMonth = String(endDateComponents.month!) + if (endDateComponents.month! < 10) + { + endDateMonth = "0".appending(endDateMonth) + } + + let rruleString = String(format: ruleFormat, String(startDateComponents.year!), startDateMonth, String(endDateComponents.year!), endDateMonth ) + + print ("rruleString: ", rruleString) + var rule = RecurrenceRule(rruleString: rruleString)! + + let occurrences = rule.allOccurrences() + print ("occurrences for rrule: ", rruleString, ", count:", occurrences.count, ", first:", occurrences.first) + if !calendar.isDate(startDate!, equalTo: occurrences.first!, toGranularity: .day) + { + print("dates mismatch, got: ", occurrences.first, ", expected: ", startDate) + } } fileprivate func testRRuleIterator() { diff --git a/Sources/Iterators.swift b/Sources/Iterators.swift index 2216377..96993ee 100644 --- a/Sources/Iterators.swift +++ b/Sources/Iterators.swift @@ -31,8 +31,7 @@ public extension RecurrenceRule { } let ruleJSONString = toJSONString(endless: endlessRecurrenceCount) - let _ = Iterator.rruleContext?.evaluateScript("var rule = new RRule({ \(ruleJSONString) })") - guard let allOccurrences = Iterator.rruleContext?.evaluateScript("rule.all()").toArray() as? [Date] else { + guard let allOccurrences = Iterator.rruleContext?.evaluateScript("new RRule({ \(ruleJSONString) }).all()").toArray() as? [Date] else { return [] } @@ -67,8 +66,7 @@ public extension RecurrenceRule { let untilDateJSON = RRule.ISO8601DateFormatter.string(from: untilDate) let ruleJSONString = toJSONString(endless: endlessRecurrenceCount) - let _ = Iterator.rruleContext?.evaluateScript("var rule = new RRule({ \(ruleJSONString) })") - guard let betweenOccurrences = Iterator.rruleContext?.evaluateScript("rule.between(new Date('\(beginDateJSON)'), new Date('\(untilDateJSON)'))").toArray() as? [Date] else { + guard let betweenOccurrences = Iterator.rruleContext?.evaluateScript("new RRule({ \(ruleJSONString) }).between(new Date('\(beginDateJSON)'), new Date('\(untilDateJSON)'))").toArray() as? [Date] else { return [] } From a4e2e8198fb0586c87c2813e2b499b8cee78ab02 Mon Sep 17 00:00:00 2001 From: Martynas Limontas Date: Fri, 8 Oct 2021 10:54:27 +0300 Subject: [PATCH 3/7] Package.swift (in progress) --- Package.swift | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Package.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..417ec71 --- /dev/null +++ b/Package.swift @@ -0,0 +1,29 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "RRuleSwift", + platforms: [ + .iOS(.v10), + .macOS(.v10_12), + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "RRuleSwift-iOS", + targets: ["RRuleSwift-iOS"]), + ], + dependencies: [ + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "RRuleSwift-iOS", + dependencies: [], +// path: "RRuleSwift-iOS" + ), + ] +) From c5a19d58d4802c6a19ba19efcc12341f715553ef Mon Sep 17 00:00:00 2001 From: Martynas Limontas Date: Fri, 8 Oct 2021 11:22:32 +0300 Subject: [PATCH 4/7] Package.swift (in progress) --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 417ec71..7c58404 100644 --- a/Package.swift +++ b/Package.swift @@ -22,7 +22,7 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "RRuleSwift-iOS", - dependencies: [], + dependencies: [] //, // path: "RRuleSwift-iOS" ), ] From e10188bccabc1da92f3cf6274f717e5b3fad95d2 Mon Sep 17 00:00:00 2001 From: Martynas Limontas Date: Fri, 8 Oct 2021 11:27:57 +0300 Subject: [PATCH 5/7] Package.swift (in progress) --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 7c58404..2752d45 100644 --- a/Package.swift +++ b/Package.swift @@ -22,8 +22,8 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "RRuleSwift-iOS", - dependencies: [] //, -// path: "RRuleSwift-iOS" + dependencies: [], + path: "" ), ] ) From cc578736a5fa5c47db48e6478d4fc0cd6c0e11ed Mon Sep 17 00:00:00 2001 From: Martynas Limontas Date: Fri, 8 Oct 2021 11:43:10 +0300 Subject: [PATCH 6/7] Package.swift (in progress) --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 2752d45..07e82ef 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,7 @@ let package = Package( .target( name: "RRuleSwift-iOS", dependencies: [], - path: "" + path: "Sources" ), ] ) From 0dff8ef52c4662004e7c4e0d467ad33396b3c200 Mon Sep 17 00:00:00 2001 From: Martynas Limontas Date: Fri, 8 Oct 2021 13:03:16 +0300 Subject: [PATCH 7/7] Package.swift (in progress) --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 07e82ef..d1d5deb 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,7 @@ let package = Package( products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( - name: "RRuleSwift-iOS", + name: "RRuleSwift", targets: ["RRuleSwift-iOS"]), ], dependencies: [