Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ Carthage/Build
fastlane/report.xml
fastlane/screenshots

.DS_Store
/archives
/RRuleSwift.xcframework
19 changes: 19 additions & 0 deletions RRule/RRule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// RRule.h
// RRule
//
// Created by Nikhil Nigade on 28/11/22.
// Copyright © 2022 Teambition. All rights reserved.
//

#import <Foundation/Foundation.h>

//! Project version number for RRule.
FOUNDATION_EXPORT double RRuleVersionNumber;

//! Project version string for RRule.
FOUNDATION_EXPORT const unsigned char RRuleVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <RRule/PublicHeader.h>


19 changes: 19 additions & 0 deletions RRuleSwift-macOS/RRuleSwift_macOS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// RRuleSwift_macOS.h
// RRuleSwift-macOS
//
// Created by Nikhil Nigade on 26/08/21.
// Copyright © 2021 Teambition. All rights reserved.
//

#import <Foundation/Foundation.h>

//! Project version number for RRuleSwift_macOS.
FOUNDATION_EXPORT double RRuleSwift_macOSVersionNumber;

//! Project version string for RRuleSwift_macOS.
FOUNDATION_EXPORT const unsigned char RRuleSwift_macOSVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <RRuleSwift_macOS/PublicHeader.h>


263 changes: 249 additions & 14 deletions RRuleSwift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
58 changes: 58 additions & 0 deletions RRuleSwift.xcodeproj/xcshareddata/xcschemes/RRule.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F0EB3A4D26D72D8E00FDA3AE"
BuildableName = "RRuleSwift.framework"
BlueprintName = "RRuleSwift-macOS"
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
67 changes: 67 additions & 0 deletions RRuleSwift.xcodeproj/xcshareddata/xcschemes/XCFramework.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F05EA10A2934C8A900B30790"
BuildableName = "XCFramework"
BlueprintName = "XCFramework"
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F05EA10A2934C8A900B30790"
BuildableName = "XCFramework"
BlueprintName = "XCFramework"
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 2 additions & 0 deletions RRuleSwiftExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/RRuleSwiftExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Teambition.RRuleSwiftExample;
PRODUCT_NAME = RRuleSwiftExample;
Expand All @@ -585,6 +586,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/RRuleSwiftExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Teambition.RRuleSwiftExample;
PRODUCT_NAME = RRuleSwiftExample;
Expand Down
1 change: 1 addition & 0 deletions RRuleSwiftExample/RRuleExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class RRuleExampleViewController: UIViewController {
print(dateFormatter.string(from: occurrence))
}
print("\n")
print("text: \(String(describing: rule.toText()))")
}

@objc func resetButtonTapped(_ sender: UIBarButtonItem) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/EKWeekday+RRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal extension EKWeekday {
}
}

extension EKWeekday: Comparable { }
extension EKWeekday: @retroactive Comparable { }

public func <(lhs: EKWeekday, rhs: EKWeekday) -> Bool {
return lhs.toNumberSymbol() < rhs.toNumberSymbol()
Expand Down
32 changes: 18 additions & 14 deletions Sources/Iterators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,41 @@ import Foundation
import JavaScriptCore

public struct Iterator {
public static let endlessRecurrenceCount = 500
public static let endlessRecurrenceCount: Int = 500

internal static let rruleContext: JSContext? = {
guard let rrulejs = JavaScriptBridge.rrulejs() else {
let scripts = JavaScriptBridge.rrulejs()
guard let rrulejs = scripts.lib,
let nlpJS = scripts.nlp else {
return nil
}
let context = JSContext()
context?.exceptionHandler = { context, exception in
print("[RRuleSwift] rrule.js error: \(String(describing: exception))")
}
let _ = context?.evaluateScript(rrulejs)
let _ = context?.evaluateScript(nlpJS)
return context
}()
}

public extension RecurrenceRule {
func allOccurrences(endless endlessRecurrenceCount: Int = Iterator.endlessRecurrenceCount) -> [Date] {
guard let _ = JavaScriptBridge.rrulejs() else {
guard let _ = JavaScriptBridge.rrulejs().lib else {
return []
}

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 {
return []
}

var occurrences = allOccurrences
if let rdates = rdate?.dates {
occurrences.append(contentsOf: rdates)
}

if let exdates = exdate?.dates, let component = exdate?.component {
for occurrence in occurrences {
for exdate in exdates {
Expand All @@ -52,31 +56,31 @@ public extension RecurrenceRule {
}
}
}

return occurrences.sorted { $0.isBeforeOrSame(with: $1) }
}

func occurrences(between date: Date, and otherDate: Date, endless endlessRecurrenceCount: Int = Iterator.endlessRecurrenceCount) -> [Date] {
guard let _ = JavaScriptBridge.rrulejs() else {
guard let _ = JavaScriptBridge.rrulejs().lib else {
return []
}

let beginDate = date.isBeforeOrSame(with: otherDate) ? date : otherDate
let untilDate = otherDate.isAfterOrSame(with: date) ? otherDate : date
let beginDateJSON = RRule.ISO8601DateFormatter.string(from: beginDate)
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 {
return []
}

var occurrences = betweenOccurrences
if let rdates = rdate?.dates {
occurrences.append(contentsOf: rdates)
}

if let exdates = exdate?.dates, let component = exdate?.component {
for occurrence in occurrences {
for exdate in exdates {
Expand All @@ -88,7 +92,7 @@ public extension RecurrenceRule {
}
}
}

return occurrences.sorted { $0.isBeforeOrSame(with: $1) }
}
}
Loading