Last active
November 7, 2017 00:53
-
-
Save ashtonmeuser/fc68ae8284d76b808c630c9b0bb71fef to your computer and use it in GitHub Desktop.
Simple time passed formatter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // DateTimePassed.swift | |
| // | |
| // Created by Ashton Meuser on 2017-08-21. | |
| // Copyright © 2017 Ashton Meuser. All rights reserved. | |
| // | |
| import Foundation | |
| extension Date { | |
| var timePassed: String { | |
| let formatter = DateComponentsFormatter() | |
| formatter.maximumUnitCount = 1 | |
| formatter.unitsStyle = .abbreviated | |
| formatter.allowedUnits = [.day, .hour, .minute] | |
| let string = formatter.string(from: self, to: Date()) | |
| return string != nil ? "\(string!) ago" : "now" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment