Skip to content

Commit

Permalink
Renamed TimePassedUnit > TimePassed and declared it outside the exten…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
Jaja Yting committed Aug 24, 2018
1 parent c40ac53 commit 637997a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Sources/DateExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

import Foundation

extension Date {
public enum TimePassed {
case year(Int)
case month(Int)
case day(Int)
case hour(Int)
case minute(Int)
case second(Int)
case now
}

public enum TimePassedUnit {
case year(Int)
case month(Int)
case day(Int)
case hour(Int)
case minute(Int)
case second(Int)
case now
}
extension Date {

public static let minutesInAWeek = 24 * 60 * 7

Expand Down Expand Up @@ -147,26 +147,26 @@ extension Date {
}

/// EZSE: Easy creation of time passed String. Can be Years, Months, days, hours, minutes or seconds. Useful for localization
public func timePassed() -> TimePassedUnit {
public func timePassed() -> TimePassed {

let date = Date()
let calendar = Calendar.autoupdatingCurrent
let components = (calendar as NSCalendar).components([.year, .month, .day, .hour, .minute, .second], from: self, to: date, options: [])

if components.year! >= 1 {
return TimePassedUnit.year(components.year!)
return TimePassed.year(components.year!)
} else if components.month! >= 1 {
return TimePassedUnit.month(components.month!)
return TimePassed.month(components.month!)
} else if components.day! >= 1 {
return TimePassedUnit.day(components.day!)
return TimePassed.day(components.day!)
} else if components.hour! >= 1 {
return TimePassedUnit.hour(components.hour!)
return TimePassed.hour(components.hour!)
} else if components.minute! >= 1 {
return TimePassedUnit.minute(components.minute!)
return TimePassed.minute(components.minute!)
} else if components.second! >= 1 {
return TimePassedUnit.second(components.second!)
return TimePassed.second(components.second!)
} else {
return TimePassedUnit.now
return TimePassed.now
}
}

Expand Down

0 comments on commit 637997a

Please sign in to comment.