Skip to content

Commit

Permalink
Refactors codebase and introduces proper time zone handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Maurice Arikoglu committed Apr 26, 2018
1 parent 8e3ffdf commit f9bc28c
Show file tree
Hide file tree
Showing 9 changed files with 798 additions and 206 deletions.
18 changes: 18 additions & 0 deletions CalendarKit-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
512ADA3A2090AFF7005F9AC2 /* CalendarTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512ADA392090AFF7005F9AC2 /* CalendarTools.swift */; };
512ADA3B2090AFF7005F9AC2 /* CalendarTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512ADA392090AFF7005F9AC2 /* CalendarTools.swift */; };
512ADA3D2090B042005F9AC2 /* ICS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512ADA3C2090B042005F9AC2 /* ICS.swift */; };
512ADA3E2090B042005F9AC2 /* ICS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512ADA3C2090B042005F9AC2 /* ICS.swift */; };
512ADA402090BA15005F9AC2 /* ICSTimeZoneParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512ADA3F2090BA15005F9AC2 /* ICSTimeZoneParser.swift */; };
512ADA412090BA15005F9AC2 /* ICSTimeZoneParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512ADA3F2090BA15005F9AC2 /* ICSTimeZoneParser.swift */; };
51873BD11FD2AA570000E9C5 /* university.ics in Resources */ = {isa = PBXBuildFile; fileRef = 51873BD01FD2AA570000E9C5 /* university.ics */; };
51873BD31FD2AAC50000E9C5 /* basic.ics in Resources */ = {isa = PBXBuildFile; fileRef = 51873BD21FD2AAC50000E9C5 /* basic.ics */; };
51873BD51FD2D6150000E9C5 /* university-formatted.ics in Resources */ = {isa = PBXBuildFile; fileRef = 51873BD41FD2D6150000E9C5 /* university-formatted.ics */; };
Expand Down Expand Up @@ -83,6 +89,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
512ADA392090AFF7005F9AC2 /* CalendarTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarTools.swift; sourceTree = "<group>"; };
512ADA3C2090B042005F9AC2 /* ICS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ICS.swift; sourceTree = "<group>"; };
512ADA3F2090BA15005F9AC2 /* ICSTimeZoneParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ICSTimeZoneParser.swift; sourceTree = "<group>"; };
51873BD01FD2AA570000E9C5 /* university.ics */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = university.ics; sourceTree = "<group>"; usesTabs = 0; wrapsLines = 1; };
51873BD21FD2AAC50000E9C5 /* basic.ics */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = basic.ics; sourceTree = "<group>"; };
51873BD41FD2D6150000E9C5 /* university-formatted.ics */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "university-formatted.ics"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.applescript; };
Expand Down Expand Up @@ -233,7 +242,10 @@
children = (
51A1D3401FD057DB00963B5F /* SwiftCal.swift */,
51A1D33B1FCF4F4600963B5F /* CalendarEvent.swift */,
512ADA392090AFF7005F9AC2 /* CalendarTools.swift */,
51A1D33E1FCF572800963B5F /* ICSEventParser.swift */,
512ADA3F2090BA15005F9AC2 /* ICSTimeZoneParser.swift */,
512ADA3C2090B042005F9AC2 /* ICS.swift */,
);
path = SwiftCal;
sourceTree = "<group>";
Expand Down Expand Up @@ -451,8 +463,11 @@
buildActionMask = 2147483647;
files = (
51873C001FD3767E0000E9C5 /* CalendarEvent.swift in Sources */,
512ADA3B2090AFF7005F9AC2 /* CalendarTools.swift in Sources */,
51873C011FD376D60000E9C5 /* ICSEventParser.swift in Sources */,
51873BFF1FD3767B0000E9C5 /* SwiftCal.swift in Sources */,
512ADA3E2090B042005F9AC2 /* ICS.swift in Sources */,
512ADA412090BA15005F9AC2 /* ICSTimeZoneParser.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -469,10 +484,13 @@
buildActionMask = 2147483647;
files = (
51A1D3041FCF4A5C00963B5F /* ViewController.swift in Sources */,
512ADA402090BA15005F9AC2 /* ICSTimeZoneParser.swift in Sources */,
51A1D33C1FCF4F4600963B5F /* CalendarEvent.swift in Sources */,
51A1D33F1FCF572800963B5F /* ICSEventParser.swift in Sources */,
512ADA3A2090AFF7005F9AC2 /* CalendarTools.swift in Sources */,
51A1D3411FD057DB00963B5F /* SwiftCal.swift in Sources */,
51A1D3021FCF4A5C00963B5F /* AppDelegate.swift in Sources */,
512ADA3D2090B042005F9AC2 /* ICS.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
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>
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>
61 changes: 61 additions & 0 deletions CalendarKit-Swift/SwiftCal/CalendarTools.swift
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
}
}
}
73 changes: 73 additions & 0 deletions CalendarKit-Swift/SwiftCal/ICS.swift
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
}

}
Loading

0 comments on commit f9bc28c

Please sign in to comment.