测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可协议 | MIT |
发布日期最后发布日期 | 2015年12月 |
SPM支持 SPM | ✗ |
由Eugene Mozharovsky 维护。
CVCalendarKit 是围绕 NSDate 的包装器,它通过重载运算符和扩展提供了一种方便处理日期的方法。
当前可用的功能。
其他更改。
下载 CVCalendarKit 项目的源代码,并将 CVCalendarKit 文件夹添加到您的目标(如有需要,请复制)。
使用 CVCalendarKit 非常简单直观。您只需要一个 NSDate 实例。
/// Current date.
let today = NSDate()
现在您可以在 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
甚至更疯狂的操作!
/// Multiplication and Division.
let multipliedDate = today.day * 5
let dividedDate = today.month / 5
您可以通过尾随操作获取复杂的计算。
/// Trailing operations.
let dayAheadMonthAgo = (today.day + 1).month - 1
let yearAheadTwoMonthsAgoFiveDaysAhead = ((today.year + 1).month - 1).day + 5
您需要比较 NSDate 实例吗?请看这里!
/// NSDate comparison.
today == yesterday
today > yesterday
yesterday <= tomorrow
tomorrow != today
您还可以得到您日期的月份/年份中的第一个/最后一个日期。
/// Convenience stuff.
let firstDateInCurrentMonth = today.firstMonthDate()
let lastDateInCurrentMonth = today.lastMonthDate()
let firstDateInCurrentYear = today.firstYearDate()
let lastDateInCurrentYear = today.lastYearDate()
您可以使用 NSDate 对象上的重载运算符 ==
构建自定义日期。
/// Date construction by assigning values.
let customDate = ((today.day == 21).month == 5).year == 1997
访问日期单位的值。
/// Date unit values (year, month, day).
let todaysYear = today.year.value()
let todaysMonth = today.month.value()
let todaysDay = today.day.value()
并获取星期枚举/原值。
/// NSDate+Weekday.
let todaysWeekday = today.weekday // Enum value.
let todaysWeekdayRaw = today.weekday.rawValue // Raw value.
CVCalendarKit 在 MIT 许可下发布。有关更多信息,请参阅 LICENSE 文件。