Skip to content

Commit

Permalink
Updated dependencies (SwiftDate, SnapKit), changed deployment target …
Browse files Browse the repository at this point in the history
…to 10.0, converted Colander to swift 5
  • Loading branch information
ag committed May 16, 2019
1 parent 5095891 commit cb49a8e
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 151 deletions.
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

10 changes: 6 additions & 4 deletions Colander.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Colander'
s.version = '0.2.2'
s.version = '0.2.3'
s.summary = 'A highly customizable iOS calendar view'

s.description = <<-DESC
Expand All @@ -14,11 +14,13 @@ Pod::Spec.new do |s|
s.author = { 'Bryan Oltman' => '[email protected]' }
s.source = { :git => 'https://github.com/blueapron/Colander.git', :tag => s.version.to_s }

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '10.0'
s.swift_version = '5.0'


s.source_files = 'Colander/Classes/**/*'

s.dependency 'SnapKit', '~> 4.0'
s.dependency 'SwiftDate', '~> 4.5.0'
s.dependency 'SnapKit', '~> 5.0.0'
s.dependency 'SwiftDate', '~> 6.0.3'

end
13 changes: 7 additions & 6 deletions Colander/Classes/CalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public class CalendarView: UIView {
let view = supplementaryViewType.init(frame: CGRect.zero)
view.setNeedsLayout()
view.layoutIfNeeded()
headerHeight = view.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height
headerHeight = view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
}

/**
Expand Down Expand Up @@ -193,7 +193,7 @@ public class CalendarView: UIView {
*/
public func select(date: Date) {
guard !selectedDates.contains(date) else { return }
selectedDates.append(date.startOfDay)
selectedDates.append(DateInRegion(date).dateAt(.startOfDay).date)
collectionView.selectItem(at: viewModel?.indexPath(from: date), animated: false, scrollPosition: [])
}

Expand All @@ -203,8 +203,9 @@ public class CalendarView: UIView {
- parameter date: the date to deselect
*/
public func deselect(date: Date) {
guard let indexPath = viewModel?.indexPath(from: date.startOfDay) else { return }
if let index = selectedDates.index(of: date.startOfDay) {
let startOfDay = DateInRegion(date).dateAt(.startOfDay).date
guard let indexPath = viewModel?.indexPath(from: startOfDay) else { return }
if let index = selectedDates.firstIndex(of: startOfDay) {
selectedDates.remove(at: index)
}
collectionView.deselectItem(at: indexPath, animated: false)
Expand Down Expand Up @@ -239,7 +240,7 @@ public class CalendarView: UIView {
- parameter position: the position to scroll to (defaults to centeredVertically)
- parameter animated: whether the scrolling should be animated (defaults to true)
*/
public func scroll(toDate date: Date, position: UICollectionViewScrollPosition = .centeredVertically, animated: Bool = true) {
public func scroll(toDate date: Date, position: UICollectionView.ScrollPosition = .centeredVertically, animated: Bool = true) {
guard let indexPath = viewModel?.indexPath(from: date) else { return }
scroll(toIndexPath: indexPath, position: position, animated: animated)
}
Expand All @@ -251,7 +252,7 @@ public class CalendarView: UIView {
- parameter position: the position to scroll to (defaults to centeredVertically)
- parameter animated: whether the scrolling should be animated (defaults to true)
*/
public func scroll(toIndexPath indexPath: IndexPath, position: UICollectionViewScrollPosition = .centeredVertically, animated: Bool = true) {
public func scroll(toIndexPath indexPath: IndexPath, position: UICollectionView.ScrollPosition = .centeredVertically, animated: Bool = true) {
collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: animated)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Colander/Classes/CalendarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CalendarViewModel {

init(startDate: Date, endDate: Date, showLeadingWeeks: Bool = true,
showTrailingWeeks: Bool = true, calendar: Calendar = Calendar.gregorian) throws {
if startDate > endDate && !startDate.isInSameDayOf(date: endDate) {
if startDate > endDate && !DateInRegion(startDate).compare(.isSameDay(endDate)) {
throw DateError.InvalidDateOrdering
}

Expand All @@ -53,7 +53,7 @@ class CalendarViewModel {
self.showLeadingWeeks = showLeadingWeeks
self.showTrailingWeeks = showTrailingWeeks
self.calendar = calendar
Date.setDefaultRegion(Region(tz: TimeZone.current, cal: calendar, loc: Locale.current))
SwiftDate.defaultRegion = Region(calendar: calendar, zone: TimeZone.current, locale: Locale.current)
self.monthInfos = try CalendarViewModel.makeMonthInfos(startDate: startDate, endDate: endDate, calendar: calendar)
}

Expand All @@ -72,7 +72,7 @@ class CalendarViewModel {
}
let zeroIndexDate = firstDisplayDate(for: section, showLeadingWeeks: showLeadingWeeks)
// 1 hour is added to make this calculation correct for the beginning of Daylight Saving Time. I don't like it either.
let intervalDiff = (date + 1.hour) - zeroIndexDate
let intervalDiff = (date + 1.hours) - zeroIndexDate
return IndexPath(item: intervalDiff.in(.day) ?? 0, section: section)
}

Expand Down
6 changes: 4 additions & 2 deletions Colander/Classes/DateExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ extension Calendar {

extension Date {
var beginningOfMonth: Date {
return self.startOf(component: .month)
var firstDayOfStartMonth = Calendar.gregorian.dateComponents( [.era, .year, .month], from: self)
firstDayOfStartMonth.day = 1
return Calendar.gregorian.date(from: firstDayOfStartMonth) ?? Date.nowAt(.startOfMonth)
}

var beginningOfWeek: Date {
return self.startOf(component: .weekOfMonth)
return Calendar.gregorian.date(from: Calendar.gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self)) ?? Date.nowAt(.startOfWeek)
}

var endOfWeek: Date {
Expand Down
Loading

0 comments on commit cb49a8e

Please sign in to comment.