An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
alpha-wallet-ios/Trust/Extensions/Date.swift

45 lines
1.2 KiB

//
// Date.swift
// Alpha-Wallet
//
// Created by Oguzhan Gungor on 2/24/18.
// Copyright © 2018 Alpha-Wallet. All rights reserved.
//
import Foundation
public extension Date {
private static var formatsMap: [String: DateFormatter] = [:]
public init?(string: String, format: String) {
let date = Date.formatter(with: format).date(from: string)
if date != nil {
self = date!
return
}
return nil
}
public func format(_ format: String) -> String {
return Date.formatter(with: format).string(from: self)
}
public static func formatter(with format: String) -> DateFormatter {
var foundFormatter = Date.formatsMap[format]
if foundFormatter == nil {
foundFormatter = DateFormatter()
foundFormatter?.dateFormat = format
Date.formatsMap[format] = foundFormatter!
}
return foundFormatter!
}
public static var yesterday: Date {
return Calendar.current.date(byAdding: .day, value: -1, to: Date())!
}
public static var tomorrow: Date {
return Calendar.current.date(byAdding: .day, value: 1, to: Date())!
}
}