Skip to content

Instantly share code, notes, and snippets.

@ashtonmeuser
Last active November 7, 2017 00:53
Show Gist options
  • Select an option

  • Save ashtonmeuser/fc68ae8284d76b808c630c9b0bb71fef to your computer and use it in GitHub Desktop.

Select an option

Save ashtonmeuser/fc68ae8284d76b808c630c9b0bb71fef to your computer and use it in GitHub Desktop.
Simple time passed formatter
//
// 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