Skip to content

Commit 5afaf13

Browse files
authored
Merge pull request #286 from GargoyleSoft/master
Removed dependency on DateToolsSwift
2 parents 6c79010 + 3388a31 commit 5afaf13

23 files changed

+77
-434
lines changed

CalendarKit.podspec

-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ Pod::Spec.new do |s|
1212
s.requires_arc = true
1313
s.source_files = 'Source/**/*'
1414
s.ios.resource_bundle = { 'CalendarKit' => ['Localizations/*.lproj'] }
15-
s.dependency 'DateToolsSwift'
1615
end

CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj

+6-16
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,22 @@
88

99
/* Begin PBXBuildFile section */
1010
75776AF58133F6BBDDCF1CE7 /* Pods_CalendarApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A223D8E39EB8C7A25F4E823A /* Pods_CalendarApp.framework */; };
11-
791ACF5023FC887D00B2D602 /* TimeChunk+DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791ACF4F23FC887D00B2D602 /* TimeChunk+DateComponents.swift */; };
1211
7924834D23CB7B58003E3D27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7924834C23CB7B58003E3D27 /* Assets.xcassets */; };
1312
7924835023CB7B58003E3D27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7924834E23CB7B58003E3D27 /* LaunchScreen.storyboard */; };
1413
7924836A23CB7BFE003E3D27 /* DatePickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924836423CB7BFE003E3D27 /* DatePickerController.swift */; };
1514
7924836B23CB7BFE003E3D27 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924836523CB7BFE003E3D27 /* AppDelegate.swift */; };
1615
7924836C23CB7BFE003E3D27 /* CustomCalendarExampleController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924836623CB7BFE003E3D27 /* CustomCalendarExampleController.swift */; };
17-
7924836D23CB7BFE003E3D27 /* ExampleController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924836723CB7BFE003E3D27 /* ExampleController.swift */; };
18-
7924836E23CB7BFE003E3D27 /* ExampleNotificationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924836823CB7BFE003E3D27 /* ExampleNotificationController.swift */; };
1916
/* End PBXBuildFile section */
2017

2118
/* Begin PBXFileReference section */
2219
786F0C3439DCA027A1D04664 /* Pods-CalendarApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CalendarApp.release.xcconfig"; path = "Target Support Files/Pods-CalendarApp/Pods-CalendarApp.release.xcconfig"; sourceTree = "<group>"; };
23-
791ACF4F23FC887D00B2D602 /* TimeChunk+DateComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeChunk+DateComponents.swift"; sourceTree = "<group>"; };
2420
7924834023CB7B57003E3D27 /* CalendarApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CalendarApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
2521
7924834C23CB7B58003E3D27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2622
7924834F23CB7B58003E3D27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2723
7924835123CB7B58003E3D27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2824
7924836423CB7BFE003E3D27 /* DatePickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatePickerController.swift; sourceTree = "<group>"; };
2925
7924836523CB7BFE003E3D27 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
30-
7924836623CB7BFE003E3D27 /* CustomCalendarExampleController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomCalendarExampleController.swift; sourceTree = "<group>"; };
31-
7924836723CB7BFE003E3D27 /* ExampleController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleController.swift; sourceTree = "<group>"; };
32-
7924836823CB7BFE003E3D27 /* ExampleNotificationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleNotificationController.swift; sourceTree = "<group>"; };
26+
7924836623CB7BFE003E3D27 /* CustomCalendarExampleController.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = CustomCalendarExampleController.swift; sourceTree = "<group>"; tabWidth = 2; };
3327
A223D8E39EB8C7A25F4E823A /* Pods_CalendarApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CalendarApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3428
FEBA81B9D67F9FBBA5381D09 /* Pods-CalendarApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CalendarApp.debug.xcconfig"; path = "Target Support Files/Pods-CalendarApp/Pods-CalendarApp.debug.xcconfig"; sourceTree = "<group>"; };
3529
/* End PBXFileReference section */
@@ -77,11 +71,8 @@
7771
isa = PBXGroup;
7872
children = (
7973
7924836523CB7BFE003E3D27 /* AppDelegate.swift */,
80-
791ACF4F23FC887D00B2D602 /* TimeChunk+DateComponents.swift */,
8174
7924836623CB7BFE003E3D27 /* CustomCalendarExampleController.swift */,
8275
7924836423CB7BFE003E3D27 /* DatePickerController.swift */,
83-
7924836723CB7BFE003E3D27 /* ExampleController.swift */,
84-
7924836823CB7BFE003E3D27 /* ExampleNotificationController.swift */,
8576
7924834C23CB7B58003E3D27 /* Assets.xcassets */,
8677
7924834E23CB7B58003E3D27 /* LaunchScreen.storyboard */,
8778
7924835123CB7B58003E3D27 /* Info.plist */,
@@ -126,7 +117,7 @@
126117
isa = PBXProject;
127118
attributes = {
128119
LastSwiftUpdateCheck = 1130;
129-
LastUpgradeCheck = 1130;
120+
LastUpgradeCheck = 1220;
130121
ORGANIZATIONNAME = "Richard Topchii";
131122
TargetAttributes = {
132123
7924833F23CB7B57003E3D27 = {
@@ -213,10 +204,7 @@
213204
buildActionMask = 2147483647;
214205
files = (
215206
7924836B23CB7BFE003E3D27 /* AppDelegate.swift in Sources */,
216-
7924836E23CB7BFE003E3D27 /* ExampleNotificationController.swift in Sources */,
217207
7924836C23CB7BFE003E3D27 /* CustomCalendarExampleController.swift in Sources */,
218-
791ACF5023FC887D00B2D602 /* TimeChunk+DateComponents.swift in Sources */,
219-
7924836D23CB7BFE003E3D27 /* ExampleController.swift in Sources */,
220208
7924836A23CB7BFE003E3D27 /* DatePickerController.swift in Sources */,
221209
);
222210
runOnlyForDeploymentPostprocessing = 0;
@@ -261,6 +249,7 @@
261249
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
262250
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
263251
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
252+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
264253
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
265254
CLANG_WARN_STRICT_PROTOTYPES = YES;
266255
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -321,6 +310,7 @@
321310
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
322311
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
323312
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
313+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
324314
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
325315
CLANG_WARN_STRICT_PROTOTYPES = YES;
326316
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -357,7 +347,7 @@
357347
CLANG_ENABLE_MODULES = YES;
358348
CODE_SIGN_STYLE = Automatic;
359349
INFOPLIST_FILE = CalendarApp/Info.plist;
360-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
350+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
361351
LD_RUNPATH_SEARCH_PATHS = (
362352
"$(inherited)",
363353
"@executable_path/Frameworks",
@@ -378,7 +368,7 @@
378368
CLANG_ENABLE_MODULES = YES;
379369
CODE_SIGN_STYLE = Automatic;
380370
INFOPLIST_FILE = CalendarApp/Info.plist;
381-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
371+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
382372
LD_RUNPATH_SEARCH_PATHS = (
383373
"$(inherited)",
384374
"@executable_path/Frameworks",

CalendarKitDemo/CalendarApp.xcodeproj/xcshareddata/xcschemes/CalendarApp.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1130"
3+
LastUpgradeVersion = "1220"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

CalendarKitDemo/CalendarApp.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>BuildSystemType</key>
6-
<string>Original</string>
6+
<string>Latest</string>
77
<key>PreviewsEnabled</key>
88
<false/>
99
</dict>

CalendarKitDemo/CalendarApp/CustomCalendarExampleController.swift

+26-75
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import UIKit
22
import CalendarKit
3-
import DateToolsSwift
43

5-
class CustomCalendarExampleController: DayViewController, DatePickerControllerDelegate {
4+
class CustomCalendarExampleController: DayViewController {
65

76
var data = [["Breakfast at Tiffany's",
87
"New York, 5th avenue"],
@@ -46,73 +45,29 @@ class CustomCalendarExampleController: DayViewController, DatePickerControllerDe
4645
UIColor.green,
4746
UIColor.red]
4847

49-
lazy var customCalendar: Calendar = {
50-
let customNSCalendar = NSCalendar(identifier: NSCalendar.Identifier.gregorian)!
51-
customNSCalendar.timeZone = TimeZone(abbreviation: "CEST")!
52-
let calendar = customNSCalendar as Calendar
53-
return calendar
48+
private lazy var rangeFormatter: DateIntervalFormatter = {
49+
let fmt = DateIntervalFormatter()
50+
fmt.dateStyle = .none
51+
fmt.timeStyle = .short
52+
53+
return fmt
5454
}()
55-
55+
5656
override func loadView() {
57-
calendar = customCalendar
57+
calendar.timeZone = TimeZone(identifier: "Europe/Paris")!
58+
5859
dayView = DayView(calendar: calendar)
5960
view = dayView
6061
}
6162

6263
override func viewDidLoad() {
6364
super.viewDidLoad()
6465
title = "CalendarKit Demo"
65-
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Change Date",
66-
style: .plain,
67-
target: self,
68-
action: #selector(ExampleController.presentDatePicker))
6966
navigationController?.navigationBar.isTranslucent = false
7067
dayView.autoScrollToFirstEvent = true
7168
reloadData()
7269
}
7370

74-
@objc func presentDatePicker() {
75-
let picker = DatePickerController()
76-
// let calendar = dayView.calendar
77-
// picker.calendar = calendar
78-
// picker.date = dayView.state!.selectedDate
79-
picker.datePicker.timeZone = TimeZone(secondsFromGMT: 0)!
80-
picker.delegate = self
81-
let navC = UINavigationController(rootViewController: picker)
82-
navigationController?.present(navC, animated: true, completion: nil)
83-
}
84-
85-
func datePicker(controller: DatePickerController, didSelect date: Date?) {
86-
if let date = date {
87-
var utcCalendar = Calendar(identifier: .gregorian)
88-
utcCalendar.timeZone = TimeZone(secondsFromGMT: 0)!
89-
90-
let offsetDate = dateOnly(date: date, calendar: dayView.calendar)
91-
92-
print(offsetDate)
93-
dayView.state?.move(to: offsetDate)
94-
}
95-
controller.dismiss(animated: true, completion: nil)
96-
}
97-
98-
func dateOnly(date: Date, calendar: Calendar) -> Date {
99-
let yearComponent = calendar.component(.year, from: date)
100-
let monthComponent = calendar.component(.month, from: date)
101-
let dayComponent = calendar.component(.day, from: date)
102-
let zone = calendar.timeZone
103-
104-
let newComponents = DateComponents(timeZone: zone,
105-
year: yearComponent,
106-
month: monthComponent,
107-
day: dayComponent)
108-
let returnValue = calendar.date(from: newComponents)
109-
110-
// let returnValue = calendar.date(bySettingHour: 0, minute: 0, second: 0, of: date)
111-
112-
113-
return returnValue!
114-
}
115-
11671
// MARK: EventDataSource
11772

11873
override func eventsForDate(_ date: Date) -> [EventDescriptor] {
@@ -124,24 +79,22 @@ class CustomCalendarExampleController: DayViewController, DatePickerControllerDe
12479
}
12580

12681
private func generateEventsForDate(_ date: Date) -> [EventDescriptor] {
127-
var workingDate = date.add(TimeChunk.dateComponents(hours: Int(arc4random_uniform(10) + 5)))
82+
var workingDate = Calendar.current.date(byAdding: .hour, value: Int.random(in: 1...15), to: date)!
12883
var events = [Event]()
12984

13085
for i in 0...4 {
13186
let event = Event()
132-
let duration = Int(arc4random_uniform(160) + 60)
133-
let datePeriod = TimePeriod(beginning: workingDate,
134-
chunk: TimeChunk.dateComponents(minutes: duration))
135-
136-
event.startDate = datePeriod.beginning!
137-
event.endDate = datePeriod.end!
138-
87+
88+
let duration = Int.random(in: 60 ... 160)
89+
event.startDate = workingDate
90+
event.endDate = Calendar.current.date(byAdding: .minute, value: duration, to: workingDate)!
91+
13992
var info = data[Int(arc4random_uniform(UInt32(data.count)))]
14093

14194
let timezone = dayView.calendar.timeZone
14295
print(timezone)
143-
info.append(datePeriod.beginning!.format(with: "dd.MM.YYYY", timeZone: timezone))
144-
info.append("\(datePeriod.beginning!.format(with: "HH:mm", timeZone: timezone)) - \(datePeriod.end!.format(with: "HH:mm", timeZone: timezone))")
96+
97+
info.append(rangeFormatter.string(from: event.startDate, to: event.endDate))
14598
event.text = info.reduce("", {$0 + $1 + "\n"})
14699
event.color = colors[Int(arc4random_uniform(UInt32(colors.count)))]
147100
event.isAllDay = Int(arc4random_uniform(2)) % 2 == 0
@@ -157,8 +110,8 @@ class CustomCalendarExampleController: DayViewController, DatePickerControllerDe
157110

158111
events.append(event)
159112

160-
let nextOffset = Int(arc4random_uniform(250) + 40)
161-
workingDate = workingDate.add(TimeChunk.dateComponents(minutes: nextOffset))
113+
let nextOffset = Int.random(in: 40 ... 250)
114+
workingDate = Calendar.current.date(byAdding: .minute, value: nextOffset, to: workingDate)!
162115
event.userInfo = String(i)
163116
}
164117

@@ -222,17 +175,15 @@ class CustomCalendarExampleController: DayViewController, DatePickerControllerDe
222175

223176
private func generateEventNearDate(_ date: Date) -> EventDescriptor {
224177
let duration = Int(arc4random_uniform(160) + 60)
225-
let startDate = date.subtract(TimeChunk.dateComponents(minutes: Int(CGFloat(duration) / 2)))
178+
let startDate = Calendar.current.date(byAdding: .minute, value: -Int(CGFloat(duration) / 2), to: date)!
226179
let event = Event()
227-
let datePeriod = TimePeriod(beginning: startDate,
228-
chunk: TimeChunk.dateComponents(minutes: duration))
229-
event.startDate = datePeriod.beginning!
230-
event.endDate = datePeriod.end!
180+
181+
event.startDate = startDate
182+
event.endDate = Calendar.current.date(byAdding: .minute, value: duration, to: startDate)!
231183

232184
var info = data[Int(arc4random_uniform(UInt32(data.count)))]
233-
let timezone = dayView.calendar.timeZone
234-
info.append(datePeriod.beginning!.format(with: "dd.MM.YYYY", timeZone: timezone))
235-
info.append("\(datePeriod.beginning!.format(with: "HH:mm", timeZone: timezone)) - \(datePeriod.end!.format(with: "HH:mm", timeZone: timezone))")
185+
186+
info.append(rangeFormatter.string(from: event.startDate, to: event.endDate))
236187
event.text = info.reduce("", {$0 + $1 + "\n"})
237188
event.color = colors[Int(arc4random_uniform(UInt32(colors.count)))]
238189
event.editedEvent = event

0 commit comments

Comments
 (0)