-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors codebase and introduces proper time zone handling
- Loading branch information
Maurice Arikoglu
committed
Apr 26, 2018
1 parent
8e3ffdf
commit f9bc28c
Showing
9 changed files
with
798 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
CalendarKit-Swift.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>BuildSystemType</key> | ||
<string>Latest</string> | ||
</dict> | ||
</plist> |
121 changes: 121 additions & 0 deletions
121
CalendarKit-Swift.xcodeproj/xcshareddata/xcschemes/CalendarKit-Swift.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "0930" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "51A1D2FD1FCF4A5C00963B5F" | ||
BuildableName = "CalendarKit-Swift.app" | ||
BlueprintName = "CalendarKit-Swift" | ||
ReferencedContainer = "container:CalendarKit-Swift.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "51A1D3111FCF4A5D00963B5F" | ||
BuildableName = "CalendarKit-SwiftTests.xctest" | ||
BlueprintName = "CalendarKit-SwiftTests" | ||
ReferencedContainer = "container:CalendarKit-Swift.xcodeproj"> | ||
</BuildableReference> | ||
</TestableReference> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "51A1D31C1FCF4A5D00963B5F" | ||
BuildableName = "CalendarKit-SwiftUITests.xctest" | ||
BlueprintName = "CalendarKit-SwiftUITests" | ||
ReferencedContainer = "container:CalendarKit-Swift.xcodeproj"> | ||
</BuildableReference> | ||
</TestableReference> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "51873BE81FD375D00000E9C5" | ||
BuildableName = "SwiftCalTests.xctest" | ||
BlueprintName = "SwiftCalTests" | ||
ReferencedContainer = "container:CalendarKit-Swift.xcodeproj"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "51A1D2FD1FCF4A5C00963B5F" | ||
BuildableName = "CalendarKit-Swift.app" | ||
BlueprintName = "CalendarKit-Swift" | ||
ReferencedContainer = "container:CalendarKit-Swift.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
<AdditionalOptions> | ||
</AdditionalOptions> | ||
</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"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "51A1D2FD1FCF4A5C00963B5F" | ||
BuildableName = "CalendarKit-Swift.app" | ||
BlueprintName = "CalendarKit-Swift" | ||
ReferencedContainer = "container:CalendarKit-Swift.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
<AdditionalOptions> | ||
</AdditionalOptions> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "51A1D2FD1FCF4A5C00963B5F" | ||
BuildableName = "CalendarKit-Swift.app" | ||
BlueprintName = "CalendarKit-Swift" | ||
ReferencedContainer = "container:CalendarKit-Swift.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// CalendarTools.swift | ||
// CalendarKit-Swift | ||
// | ||
// Created by Maurice Arikoglu on 25.04.18. | ||
// Copyright © 2018 Maurice Arikoglu. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum GregorianCalendarWeek: Int { | ||
case sunday = 1 | ||
case monday | ||
case tuesday | ||
case wednesday | ||
case thursday | ||
case friday | ||
case saturday | ||
|
||
func icsIdentifier() -> String { | ||
switch self.rawValue { | ||
case 1: | ||
return "SU" | ||
case 2: | ||
return "MO" | ||
case 3: | ||
return "TU" | ||
case 4: | ||
return "WE" | ||
case 5: | ||
return "TH" | ||
case 6: | ||
return "FR" | ||
case 7: | ||
return "SA" | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
static func fromICS(ics: String) -> GregorianCalendarWeek? { | ||
switch ics { | ||
case "SU": | ||
return .sunday | ||
case "MO": | ||
return .monday | ||
case "TU": | ||
return .tuesday | ||
case "WE": | ||
return .wednesday | ||
case "TH": | ||
return .thursday | ||
case "FR": | ||
return .friday | ||
case "SA": | ||
return .saturday | ||
default: | ||
return nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// iCalendar.swift | ||
// CalendarKit-Swift | ||
// | ||
// Created by Maurice Arikoglu on 25.04.18. | ||
// Copyright © 2018 Maurice Arikoglu. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
internal struct ICSEventKey { | ||
|
||
static let exceptionDate = "EXDATE;" | ||
static let exceptionRule = "EXRULE:" | ||
static let recurrenceRule = "RRULE:" | ||
static let transparent = "TRANSP:" | ||
static let summary = "SUMMARY:" | ||
static let status = "STATUS:" | ||
static let organizer = "ORGANIZER;" | ||
static let organizer2 = "ORGANIZER:" | ||
static let sequence = "SEQUENCE:" | ||
static let location = "LOCATION:" | ||
static let lastModified = "LAST-MODIFIED:" | ||
static let description = "DESCRIPTION:" | ||
static let description2 = "DESCRIPTION;" | ||
static let created = "CREATED:" | ||
static let recurrenceId = "RECURRENCE-ID;TZID=%@" | ||
static let attendee = "ATTENDEE;" | ||
static let uniqueId = "UID:" | ||
static let timestamp = "DTSTAMP:" | ||
static let endDate = "DTEND:" | ||
static let endDateValueDate = "DTEND;VALUE=DATE:" | ||
static let endDateAndTimezone = "DTEND;TZID=%@:" | ||
static let startDate = "DTSTART:" | ||
static let startDateValueDate = "DTSTART;VALUE=DATE:" | ||
static let startDateAndTimezone = "DTSTART;TZID=%@:" | ||
static let timezone = "TZID:" | ||
static let timezoneStartDateAndTimezone = "DTSTART;TZID=" | ||
static let timezoneBegin = "BEGIN:VTIMEZONE" | ||
static let timezoneEnd = "END:VTIMEZONE" | ||
static let eventBegin = "BEGIN:VEVENT" | ||
static let eventEnd = "END:VEVENT" | ||
static let daylightBegin = "BEGIN:DAYLIGHT" | ||
static let daylightEnd = "END:DAYLIGHT" | ||
static let standardBegin = "BEGIN:STANDARD" | ||
static let standardEnd = "END:STANDARD" | ||
static let timezoneOffsetTo = "TZOFFSETTO:" | ||
static let timezoneOffsetFrom = "TZOFFSETFROM:" | ||
static let timezoneName = "TZNAME:" | ||
} | ||
|
||
extension Date { | ||
|
||
public func set(month: Int, weekday: Int, ordinal: Int? = nil) -> Date { | ||
|
||
let currentYear = Calendar.current.component(.year, from: self) | ||
|
||
var components = DateComponents() | ||
components.year = currentYear | ||
components.month = month | ||
components.weekday = weekday | ||
components.weekdayOrdinal = ordinal | ||
|
||
guard | ||
let date = Calendar.current.date(from: components) | ||
else { | ||
print("Could not modify date") | ||
return self | ||
} | ||
return date | ||
} | ||
|
||
} |
Oops, something went wrong.