CVCalendarKit
A wrapper around NSDate which provides a convenience way for dealing with dates.
Install / Use
/learn @mozharovsky/CVCalendarKitREADME

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 construction with String
- Date unit values
- Weekdays
Further changes.
- [ ] NSCalendar wrapper
- [ ] Simplifyig the process of working with events
- [ ] Reading/Writing calendar data
Setup
<h4>Requirements.</h4> * Swift 1.2 * iOS 7 or higher <h4>CocoaPods.</h4>pod 'CVCalendarKit', '~> 0.1.5'
<h4>Manual setup.</h4>
Download CVCalendarKit project source code and add <b>CVCalendarKit</b> folder into your target (copy if needed).
Usage
Using <b>CVCalendarKit</b> is extremely easy and intuitive. All you need is an instance of a <b>NSDate</b>.
/// Current date.
let today = NSDate()
Now you can use addition and substraction on a <b>DateUnit</b>.
/// 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 - 2).day + 5
<b>NSDate</b> String description.
/// Date description.
let date = (NSDate().month == 5).descriptionWithLocale(nil, format: .DDMMYY, style: nil)
Constructing a date from its description String.
/// Date from String (its description).
if let myDate = "May 21, 1997".date(.DDMMYY, style: .MediumStyle) {
// Further stuff...
}
Do you need to compare <b>NSDate</b> 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 <b>NSDate</b> 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
- Author Eugene Mozharovsky
- Inspired by Timepiece and SwiftMoment
License
CVCalendarKit is released under the MIT license. For more information see the LICENSE file.
Related Skills
node-connect
339.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.8kCommit, push, and open a PR
