     
 }
 
-extension DateFormatter {
+public extension DateFormatter {
     
-    public func format(dateFormat: String) -> DateFormatter {
+    enum Format: String {
+        case Date = "yyyy-MM-dd"
+        case DateTime = "yyyy-MM-dd HH:mm:ss ZZZZ"
+    }
+
+    func format(dateFormat: String) -> DateFormatter {
         let dateFormatter = DateFormatter()
         dateFormatter.dateFormat = dateFormat;
         dateFormatter.timeZone = TimeZone.init(secondsFromGMT: -8 * 3600)!;

public extension String {

    public func toDate() -> Date? {
        return format(DateFormat.Date)
    }
    
    public func toDateTime() -> Date? {
        return format(DateFormat.DateTime)
    }
    
    func format(_ dateFormat: String = DateFormat.DateTime) -> Date? {
        return DateFormatter().format(dateFormat: dateFormat).date(from: self) as Date?
    }
    
    func urlSafeBase64() -> String {


import Foundation

public extension Date {
    
    public func toDateString() -> String {
        return format(.Date)
    }
    
    public func toDateTimeString() -> String {
        return format(.DateTime)
    }
    
    public func format(_ dateFormat: DateFormatter.Format = .DateTime) -> String {
        return DateFormatter().format(dateFormat: dateFormat.rawValue).string(from: self)
    }
    
    public init(dateString: String, _ format: DateFormatter.Format = .DateTime) {
        
        let dateFormatter = DateFormatter().format(dateFormat: format.rawValue)
        guard let date = dateFormatter.date(from: dateString) else {
            self = Date()
            return
