CVCalendarKit 0.1.5

CVCalendarKit 0.1.5

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2015
SPMSupports SPM

Maintained by Eugene Mozharovsky.



  • By
  • Eugene Mozharovsky

CVCalendarKit is a wrapper around NSDate which provides a convenience way for dealing with dates through overloaded operators and extensions.

Features

Currently available features.

  • DateUnit operations (year, month, day) – multiplication, division, addition, subtraction
  • Trailing operations
  • NSDate comparison
  • NSDate convenience stuff
  • Date construction with custom values
  • Date unit values
  • Weekdays

Further changes.

  • [ ] NSCalendar wrapper
  • [ ] Simplifyig the process of working with events
  • [ ] Reading/Writing calendar data

Setup

Requirements.

  • Swift 1.2
  • iOS 7 or higher

Manual setup.

Download CVCalendarKit project source code and add CVCalendarKit folder into your target (copy if needed).

Usage

Using CVCalendarKit is extremely easy and intuitive. All you need is an instance of a NSDate.

/// Current date.
let today = NSDate()

Now you can use addition and substraction on a DateUnit.

/// Day operations.
let tomorrow = today.day + 1
let yesterday = today.day - 1

/// Month operations.
let monthAhead = today.month + 1
let monthAgo = today.month - 1

/// Year operations.
let yearAhead = today.year + 1
let yearAgo = today.year - 1

Or even crazier operations!

/// Multiplication and Division.
let multipliedDate = today.day * 5
let dividedDate = today.month / 5

You can get really difficult calculations with trailing.

/// Trailing operations. 
let dayAheadMonthAgo = (today.day + 1).month - 1
let yearAheadTwoMonthsAgoFiveDaysAhead = ((today.year + 1).month - 1).day + 5

Do you need to compare NSDate instances? Here you go!

/// NSDate comparison. 
today == yesterday
today > yesterday
yesterday <= tomorrow
tomorrow != today

You can also get the first/last date in your date’s month/year.

/// Convenience stuff. 
let firstDateInCurrentMonth = today.firstMonthDate()
let lastDateInCurrentMonth = today.lastMonthDate()
let firstDateInCurrentYear = today.firstYearDate()
let lastDateInCurrentYear = today.lastYearDate()

Custom date can be constructed using == overloaded operator on NSDate objects.

/// Date construction by assigning values. 
let customDate = ((today.day == 21).month == 5).year == 1997

Accessing date units’ values.

/// Date unit values (year, month, day). 
let todaysYear = today.year.value()
let todaysMonth = today.month.value()
let todaysDay = today.day.value()

And getting weekday enum/raw value.

/// NSDate+Weekday.
let todaysWeekday = today.weekday // Enum value. 
let todaysWeekdayRaw = today.weekday.rawValue // Raw value.

Acknowledgments

License

CVCalendarKit is released under the MIT license. For more information see the LICENSE file.