0001
0009 import Foundation
0010
0011
0013 extension Int {
0014 public var era| Punctual.swift:20 | return self.era |
: NSDateComponents {
0015 let components = NSDateComponents()
0016 components.era = self
0017 return components
0018 }
0019 public var eras: NSDateComponents {
0020 return self.era
0021 }
0022 public var year| Punctual.swift:28 | return self.year |
: NSDateComponents {
0023 let components = NSDateComponents()
0024 components.year = self
0025 return components
0026 }
0027 public var years: NSDateComponents {
0028 return self.year
0029 }
0030 public var month| Punctual.swift:36 | return self.month |
: NSDateComponents {
0031 let components = NSDateComponents()
0032 components.month = self
0033 return components
0034 }
0035 public var months: NSDateComponents {
0036 return self.month
0037 }
0038 public var day| Punctual.swift:44 | return self.day |
: NSDateComponents {
0039 let components = NSDateComponents()
0040 components.day = self
0041 return components
0042 }
0043 public var days: NSDateComponents {
0044 return self.day
0045 }
0046 public var hour| Punctual.swift:52 | return self.hour |
: NSDateComponents {
0047 let components = NSDateComponents()
0048 components.hour = self
0049 return components
0050 }
0051 public var hours: NSDateComponents {
0052 return self.hour
0053 }
0054 public var minute| Punctual.swift:60 | return self.minute |
: NSDateComponents {
0055 let components = NSDateComponents()
0056 components.minute = self
0057 return components
0058 }
0059 public var minutes: NSDateComponents {
0060 return self.minute
0061 }
0062 public var second| Punctual.swift:68 | return self.second |
: NSDateComponents {
0063 let components = NSDateComponents()
0064 components.second = self
0065 return components
0066 }
0067 public var seconds: NSDateComponents {
0068 return self.second
0069 }
0070 public var nanosecond| Punctual.swift:76 | return self.nanosecond |
: NSDateComponents {
0071 let components = NSDateComponents()
0072 components.nanosecond = self
0073 return components
0074 }
0075 public var nanoseconds| Punctual.swift:79 | return (1000000 * self).nanoseconds |
: NSDateComponents {
0076 return self.nanosecond
0077 }
0078 public var millisecond| Punctual.swift:82 | return self.millisecond |
: NSDateComponents {
0079 return (1000000 * self).nanoseconds
0080 }
0081 public var milliseconds: NSDateComponents {
0082 return self.millisecond
0083 }
0084 public var weekday| Punctual.swift:90 | return self.weekday |
: NSDateComponents {
0085 let components = NSDateComponents()
0086 components.weekday = self
0087 return components
0088 }
0089 public var weekdays: NSDateComponents {
0090 return self.weekday
0091 }
0092 public var weekdayOrdinal| Punctual.swift:98 | return self.weekdayOrdinal |
: NSDateComponents {
0093 let components = NSDateComponents()
0094 components.weekdayOrdinal = self
0095 return components
0096 }
0097 public var weekdayOrdinals: NSDateComponents {
0098 return self.weekdayOrdinal
0099 }
0100 public var quarter| Punctual.swift:106 | return self.quarter |
: NSDateComponents {
0101 let components = NSDateComponents()
0102 components.quarter = self
0103 return components
0104 }
0105 public var quarters: NSDateComponents {
0106 return self.quarter
0107 }
0108 public var weekOfMonth| Punctual.swift:114 | return self.weekOfMonth |
: NSDateComponents {
0109 let components = NSDateComponents()
0110 components.weekOfMonth = self
0111 return components
0112 }
0113 public var weeksOfMonth: NSDateComponents {
0114 return self.weekOfMonth
0115 }
0116 public var weekOfYear| Punctual.swift:122 | return self.weekOfYear |
: NSDateComponents {
0117 let components = NSDateComponents()
0118 components.weekOfYear = self
0119 return components
0120 }
0121 public var weeksOfYear: NSDateComponents {
0122 return self.weekOfYear
0123 }
0124 public var yearForWeekOfYear| Punctual.swift:130 | return self.yearForWeekOfYear |
: NSDateComponents {
0125 let components = NSDateComponents()
0126 components.yearForWeekOfYear = self
0127 return components
0128 }
0129 public var yearsForWeekOfYear: NSDateComponents {
0130 return self.yearForWeekOfYear
0131 }
0132 }
0133
0134
0136 extension NSDateComponents {
0137 returns public var ago: NSDate? {
0139 return self.until(NSDate())
0140 }
0141
0142 returns public var fromNow: NSDate? {
0144 return self.from(NSDate())
0145 }
0146
0147 returns public func from| Punctual.swift:144 | return self.from(NSDate()) |
| Punctual.swift:154 | return (-self).from(date) |
| Punctual.swift:437 | return rhs.from(lhs) |
(date: NSDate) -> NSDate? {
0149 return NSCalendar.currentCalendar().dateByAddingComponents(self, toDate: date, options: [])
0150 }
0151
0152 returns public func until| Punctual.swift:139 | return self.until(NSDate()) |
(date: NSDate) -> NSDate? {
0154 return (-self).from(date)
0155 }
0156
0157 public var timeInterval: NSTimeInterval? {
0159 let templateDate = NSDate()
0160 let finalDate = templateDate + self
0161 return finalDate?.timeIntervalSinceDate(templateDate)
0162 }
0163 }
0164
0165 internal func applyIfDefined| Punctual.swift:206 | components.era = applyIfDefined(lhs.era, rhs.era, transform) |
| Punctual.swift:207 | components.year = applyIfDefined(lhs.year, rhs.year, transform) |
| Punctual.swift:208 | components.month = applyIfDefined(lhs.month, rhs.month, transform) |
| Punctual.swift:209 | components.day = applyIfDefined(lhs.day, rhs.day, transform) |
| Punctual.swift:210 | components.hour = applyIfDefined(lhs.hour, rhs.hour, transform) |
| Punctual.swift:211 | components.minute = applyIfDefined(lhs.minute, rhs.minute, transform) |
| Punctual.swift:212 | components.second = applyIfDefined(lhs.second, rhs.second, transform) |
| Punctual.swift:213 | components.nanosecond = applyIfDefined(lhs.nanosecond, rhs.nanosecond, transform) |
| Punctual.swift:214 | components.weekday = applyIfDefined(lhs.weekday, rhs.weekday, transform) |
| Punctual.swift:215 | components.weekdayOrdinal = applyIfDefined(lhs.weekdayOrdinal, rhs.weekdayOrdinal, transform) |
| Punctual.swift:216 | components.quarter = applyIfDefined(lhs.quarter, rhs.quarter, transform) |
| Punctual.swift:217 | components.weekOfMonth = applyIfDefined(lhs.weekOfMonth, rhs.weekOfMonth, transform) |
| Punctual.swift:218 | components.weekOfYear = applyIfDefined(lhs.weekOfYear, rhs.weekOfYear, transform) |
| Punctual.swift:219 | components.yearForWeekOfYear = applyIfDefined(lhs.yearForWeekOfYear, rhs.yearForWeekOfYear, transform) |
(int: Int, _ otherInt: Int, _ transform: (Int, Int) -> Int) -> Int{
0168 switch (int, otherInt) {
0169 case (_, Int(NSDateComponentUndefined)): return transform(0, int)
0170 case (Int(NSDateComponentUndefined), _): return transform(0, otherInt)
0171 default: return transform(int, otherInt)
0172 }
0173 }
0174
0175 internal func applyIfDefined| Punctual.swift:185 | components.era = applyIfDefined(rhs.era, -) |
| Punctual.swift:186 | components.year = applyIfDefined(rhs.year, -) |
| Punctual.swift:187 | components.month = applyIfDefined(rhs.month, -) |
| Punctual.swift:188 | components.day = applyIfDefined(rhs.day, -) |
| Punctual.swift:189 | components.hour = applyIfDefined(rhs.hour, -) |
| Punctual.swift:190 | components.minute = applyIfDefined(rhs.minute, -) |
| Punctual.swift:191 | components.second = applyIfDefined(rhs.second, -) |
| Punctual.swift:192 | components.nanosecond = applyIfDefined(rhs.nanosecond, -) |
| Punctual.swift:193 | components.weekday = applyIfDefined(rhs.weekday, -) |
| Punctual.swift:194 | components.weekdayOrdinal = applyIfDefined(rhs.weekdayOrdinal, -) |
| Punctual.swift:195 | components.quarter = applyIfDefined(rhs.quarter, -) |
| Punctual.swift:196 | components.weekOfMonth = applyIfDefined(rhs.weekOfMonth, -) |
| Punctual.swift:197 | components.weekOfYear = applyIfDefined(rhs.weekOfYear, -) |
| Punctual.swift:198 | components.yearForWeekOfYear = applyIfDefined(rhs.yearForWeekOfYear, -) |
(int: Int, _ transform: Int -> Int) -> Int{
0178 return int == Int(NSDateComponentUndefined) ? int : transform(int)
0179 }
0180
0181 returnspublic prefix func -(rhs: NSDateComponents) -> NSDateComponents {
0184 let components = NSDateComponents()
0185 components.era = applyIfDefined(rhs.era, -)
0186 components.year = applyIfDefined(rhs.year, -)
0187 components.month = applyIfDefined(rhs.month, -)
0188 components.day = applyIfDefined(rhs.day, -)
0189 components.hour = applyIfDefined(rhs.hour, -)
0190 components.minute = applyIfDefined(rhs.minute, -)
0191 components.second = applyIfDefined(rhs.second, -)
0192 components.nanosecond = applyIfDefined(rhs.nanosecond, -)
0193 components.weekday = applyIfDefined(rhs.weekday, -)
0194 components.weekdayOrdinal = applyIfDefined(rhs.weekdayOrdinal, -)
0195 components.quarter = applyIfDefined(rhs.quarter, -)
0196 components.weekOfMonth = applyIfDefined(rhs.weekOfMonth, -)
0197 components.weekOfYear = applyIfDefined(rhs.weekOfYear, -)
0198 components.yearForWeekOfYear = applyIfDefined(rhs.yearForWeekOfYear, -)
0199 return components
0200 }
0201
0202 private func combine| Punctual.swift:225 | return combine(lhs, rhs: rhs, transform: +) |
(lhs: NSDateComponents, rhs: NSDateComponents, transform: (Int, Int) -> Int) -> NSDateComponents {
0205 let components = NSDateComponents()
0206 components.era = applyIfDefined(lhs.era, rhs.era, transform)
0207 components.year = applyIfDefined(lhs.year, rhs.year, transform)
0208 components.month = applyIfDefined(lhs.month, rhs.month, transform)
0209 components.day = applyIfDefined(lhs.day, rhs.day, transform)
0210 components.hour = applyIfDefined(lhs.hour, rhs.hour, transform)
0211 components.minute = applyIfDefined(lhs.minute, rhs.minute, transform)
0212 components.second = applyIfDefined(lhs.second, rhs.second, transform)
0213 components.nanosecond = applyIfDefined(lhs.nanosecond, rhs.nanosecond, transform)
0214 components.weekday = applyIfDefined(lhs.weekday, rhs.weekday, transform)
0215 components.weekdayOrdinal = applyIfDefined(lhs.weekdayOrdinal, rhs.weekdayOrdinal, transform)
0216 components.quarter = applyIfDefined(lhs.quarter, rhs.quarter, transform)
0217 components.weekOfMonth = applyIfDefined(lhs.weekOfMonth, rhs.weekOfMonth, transform)
0218 components.weekOfYear = applyIfDefined(lhs.weekOfYear, rhs.weekOfYear, transform)
0219 components.yearForWeekOfYear = applyIfDefined(lhs.yearForWeekOfYear, rhs.yearForWeekOfYear, transform)
0220 return components
0221 }
0222
0223 public func +(lhs: NSDateComponents, rhs: NSDateComponents) -> NSDateComponents {
0225 return combine(lhs, rhs: rhs, transform: +)
0226 }
0227
0228 public func -(lhs: NSDateComponents, rhs: NSDateComponents) -> NSDateComponents {
0230 return lhs + (-rhs)
0231 }
0232
0233
0235 extension NSDate: Comparable {
0236 private struct Constants| Punctual.swift:265 | return self.minutes > (Constants.minutesPerHour / 2) ? self.hour + 1 : self.hour |
| Punctual.swift:269 | Constants.formatter.dateFormat = format |
| Punctual.swift:270 | let date = Constants.formatter.stringFromDate(self) |
| Punctual.swift:271 | Constants.formatter.dateFormat = nil |
| Punctual.swift:276 | Constants.formatter.dateStyle = dateStyle |
| Punctual.swift:277 | Constants.formatter.timeStyle = timeStyle |
| Punctual.swift:278 | let date = Constants.formatter.stringFromDate(self) |
| Punctual.swift:279 | Constants.formatter.dateStyle = .NoStyle |
| Punctual.swift:280 | Constants.formatter.timeStyle = .NoStyle |
{
0237 static let formatter| Punctual.swift:269 | Constants.formatter.dateFormat = format |
| Punctual.swift:270 | let date = Constants.formatter.stringFromDate(self) |
| Punctual.swift:271 | Constants.formatter.dateFormat = nil |
| Punctual.swift:276 | Constants.formatter.dateStyle = dateStyle |
| Punctual.swift:277 | Constants.formatter.timeStyle = timeStyle |
| Punctual.swift:278 | let date = Constants.formatter.stringFromDate(self) |
| Punctual.swift:279 | Constants.formatter.dateStyle = .NoStyle |
| Punctual.swift:280 | Constants.formatter.timeStyle = .NoStyle |
= NSDateFormatter()
0240 static let minutesPerHour| Punctual.swift:265 | return self.minutes > (Constants.minutesPerHour / 2) ? self.hour + 1 : self.hour |
= 60
0241 }
0242 @available(iOS, introduced=8.0)
0243 public var isToday: Bool {
0244 return NSCalendar.currentCalendar().isDateInToday(self)
0245 }
0246 @available(iOS, introduced=8.0)
0247 public var isYesterday: Bool {
0248 return NSCalendar.currentCalendar().isDateInYesterday(self)
0249 }
0250 @available(iOS, introduced=8.0)
0251 public var isTomorrow: Bool {
0252 return NSCalendar.currentCalendar().isDateInTomorrow(self)
0253 }
0254 @available(iOS, introduced=8.0)
0255 public var isWeekend: Bool {
0256 return NSCalendar.currentCalendar().isDateInWeekend(self)
0257 }
0258 public var isInPast: Bool {
0259 return self < NSDate()
0260 }
0261 public var isInFuture: Bool {
0262 return self > NSDate()
0263 }
0264 public var nearestHour: Int {
0265 return self.minutes > (Constants.minutesPerHour / 2) ? self.hour + 1 : self.hour
0266 }
0267
0268 public func stringWithFormat(format: String) -> String {
0269 Constants.formatter.dateFormat = format
0270 let date = Constants.formatter.stringFromDate(self)
0271 Constants.formatter.dateFormat = nil
0272 return date
0273 }
0274
0275 public func stringWithDateStyle| Punctual.swift:285 | return self.stringWithDateStyle(.ShortStyle, timeStyle: .ShortStyle) |
| Punctual.swift:289 | return self.stringWithDateStyle(.NoStyle, timeStyle: .ShortStyle) |
| Punctual.swift:293 | return self.stringWithDateStyle(.ShortStyle, timeStyle: .NoStyle) |
| Punctual.swift:297 | return self.stringWithDateStyle(.MediumStyle, timeStyle: .MediumStyle) |
| Punctual.swift:301 | return self.stringWithDateStyle(.NoStyle, timeStyle: .MediumStyle) |
| Punctual.swift:305 | return self.stringWithDateStyle(.MediumStyle, timeStyle: .NoStyle) |
| Punctual.swift:309 | return self.stringWithDateStyle(.LongStyle, timeStyle: .LongStyle) |
| Punctual.swift:313 | return self.stringWithDateStyle(.NoStyle, timeStyle: .LongStyle) |
| Punctual.swift:317 | return self.stringWithDateStyle(.LongStyle, timeStyle: .NoStyle) |
(dateStyle: NSDateFormatterStyle, timeStyle: NSDateFormatterStyle) -> String {
0276 Constants.formatter.dateStyle = dateStyle
0277 Constants.formatter.timeStyle = timeStyle
0278 let date = Constants.formatter.stringFromDate(self)
0279 Constants.formatter.dateStyle = .NoStyle
0280 Constants.formatter.timeStyle = .NoStyle
0281 return date
0282 }
0283
0284 public var shortString: String {
0285 return self.stringWithDateStyle(.ShortStyle, timeStyle: .ShortStyle)
0286 }
0287
0288 public var shortTimeString: String {
0289 return self.stringWithDateStyle(.NoStyle, timeStyle: .ShortStyle)
0290 }
0291
0292 public var shortDateString: String {
0293 return self.stringWithDateStyle(.ShortStyle, timeStyle: .NoStyle)
0294 }
0295
0296 public var mediumString: String {
0297 return self.stringWithDateStyle(.MediumStyle, timeStyle: .MediumStyle)
0298 }
0299
0300 public var mediumTimeString: String {
0301 return self.stringWithDateStyle(.NoStyle, timeStyle: .MediumStyle)
0302 }
0303
0304 public var mediumDateString: String {
0305 return self.stringWithDateStyle(.MediumStyle, timeStyle: .NoStyle)
0306 }
0307
0308 public var longString: String {
0309 return self.stringWithDateStyle(.LongStyle, timeStyle: .LongStyle)
0310 }
0311
0312 public var longTimeString: String {
0313 return self.stringWithDateStyle(.NoStyle, timeStyle: .LongStyle)
0314 }
0315
0316 public var longDateString: String {
0317 return self.stringWithDateStyle(.LongStyle, timeStyle: .NoStyle)
0318 }
0319
0320 public var era| Punctual.swift:324 | return self.era |
: Int {
0321 return self.components.era
0322 }
0323 public var eras: Int {
0324 return self.era
0325 }
0326 public var year| Punctual.swift:330 | return self.year |
: Int {
0327 return self.components.year
0328 }
0329 public var years: Int {
0330 return self.year
0331 }
0332 public var month| Punctual.swift:336 | return self.month |
: Int {
0333 return self.components.month
0334 }
0335 public var months: Int {
0336 return self.month
0337 }
0338 public var day| Punctual.swift:342 | return self.day |
: Int {
0339 return self.components.day
0340 }
0341 public var days: Int {
0342 return self.day
0343 }
0344 public var hour| Punctual.swift:265 | return self.minutes > (Constants.minutesPerHour / 2) ? self.hour + 1 : self.hour |
| Punctual.swift:265 | return self.minutes > (Constants.minutesPerHour / 2) ? self.hour + 1 : self.hour |
| Punctual.swift:348 | return self.hour |
: Int {
0345 return self.components.hour
0346 }
0347 public var hours: Int {
0348 return self.hour
0349 }
0350 public var minute| Punctual.swift:354 | return self.minute |
: Int {
0351 return self.components.minute
0352 }
0353 public var minutes| Punctual.swift:265 | return self.minutes > (Constants.minutesPerHour / 2) ? self.hour + 1 : self.hour |
: Int {
0354 return self.minute
0355 }
0356 public var second| Punctual.swift:360 | return self.second |
: Int {
0357 return self.components.second
0358 }
0359 public var seconds: Int {
0360 return self.second
0361 }
0362 public var nanosecond| Punctual.swift:366 | return self.nanosecond |
: Int {
0363 return self.components.nanosecond
0364 }
0365 public var nanoseconds: Int {
0366 return self.nanosecond
0367 }
0368 public var weekday| Punctual.swift:372 | return self.weekday |
: Int {
0369 return self.components.weekday
0370 }
0371 public var weekdays: Int {
0372 return self.weekday
0373 }
0374 public var weekdayOrdinal| Punctual.swift:378 | return self.weekdayOrdinal |
: Int {
0375 return self.components.weekdayOrdinal
0376 }
0377 public var weekdayOrdinals: Int {
0378 return self.weekdayOrdinal
0379 }
0380 public var quarter| Punctual.swift:384 | return self.quarter |
: Int {
0381 return self.components.quarter
0382 }
0383 public var quarters: Int {
0384 return self.quarter
0385 }
0386 public var weekOfMonth| Punctual.swift:390 | return self.weekOfMonth |
: Int {
0387 return self.components.weekOfMonth
0388 }
0389 public var weekOfMonths: Int {
0390 return self.weekOfMonth
0391 }
0392 public var weekOfYear| Punctual.swift:396 | return self.weekOfYear |
: Int {
0393 return self.components.weekOfYear
0394 }
0395 public var weekOfYears: Int {
0396 return self.weekOfYear
0397 }
0398 public var yearForWeekOfYear| Punctual.swift:402 | return self.yearForWeekOfYear |
: Int {
0399 return self.components.yearForWeekOfYear
0400 }
0401 public var yearForWeekOfYears: Int {
0402 return self.yearForWeekOfYear
0403 }
0404 public var components| Punctual.swift:321 | return self.components.era |
| Punctual.swift:327 | return self.components.year |
| Punctual.swift:333 | return self.components.month |
| Punctual.swift:339 | return self.components.day |
| Punctual.swift:345 | return self.components.hour |
| Punctual.swift:351 | return self.components.minute |
| Punctual.swift:357 | return self.components.second |
| Punctual.swift:363 | return self.components.nanosecond |
| Punctual.swift:369 | return self.components.weekday |
| Punctual.swift:375 | return self.components.weekdayOrdinal |
| Punctual.swift:381 | return self.components.quarter |
| Punctual.swift:387 | return self.components.weekOfMonth |
| Punctual.swift:393 | return self.components.weekOfYear |
| Punctual.swift:399 | return self.components.yearForWeekOfYear |
: NSDateComponents {
0405 return NSCalendar.currentCalendar().components(NSCalendarUnit.allValues, fromDate: self)
0406 }
0407 public class func fromComponents(components: NSDateComponents) -> NSDate? {
0408 return NSCalendar.currentCalendar().dateFromComponents(components)
0409 }
0410 }
0411
0412 extension NSCalendarUnit {
0413 static var allValues| Punctual.swift:405 | return NSCalendar.currentCalendar().components(NSCalendarUnit.allValues, fromDate: self) |
| Punctual.swift:432 | return NSCalendar.currentCalendar().components(NSCalendarUnit.allValues, fromDate: rhs, toDate: lhs, options: .MatchStrictly) |
: NSCalendarUnit {
0415 return [.Era, .Year, .Month, .Day, .Hour, .Minute, .Second, .Weekday, .WeekdayOrdinal, .Quarter, .WeekOfMonth, .WeekOfYear, .YearForWeekOfYear, .Nanosecond, .Calendar, .TimeZone]
0416 }
0417 }
0418
0419 public func <(lhs: NSDate, rhs: NSDate) -> Bool {
0420 return lhs.compare(rhs) == .OrderedAscending
0421 }
0422
0423 public func ==(lhs: NSDate, rhs: NSDate) -> Bool {
0424 return lhs.isEqualToDate(rhs)
0425 }
0426
0427 public func -(lhs: NSDate, rhs: NSDate) -> NSDateComponents {
0432 return NSCalendar.currentCalendar().components(NSCalendarUnit.allValues, fromDate: rhs, toDate: lhs, options: .MatchStrictly)
0433 }
0434
0435 public func +(lhs: NSDate, rhs: NSDateComponents) -> NSDate? {
0437 return rhs.from(lhs)
0438 }
0439
0440 public func +(lhs: NSDateComponents, rhs: NSDate) -> NSDate? {
0442 return rhs + lhs
0443 }
0444
0445 public func -(lhs: NSDate, rhs: NSDateComponents) -> NSDate? {
0447 return lhs + (-rhs)
0448 }
0449