//
//  DateTimeManipulation.swift
//  Noted
//
//  Created by Michael Andrew Auer on 3/19/16.
//  Copyright © 2016 Usonia LLC. All rights reserved.
//

import Foundation

struct DateTime {
    
    let df: NSDateFormatter = NSDateFormatter()
    
    init() {
        df.dateFormat = "yyyy-MM-dd HH:mm:ss"
    }
    func fmtDate(noteDate: String) -> String {
        if (noteDate == "") {
            return ""
        }
        
        let noteNSD: NSDate = df.dateFromString(noteDate)!
        let difference = -(noteNSD.timeIntervalSinceNow)
        let oneday: Double = 86400
        
        if (difference < oneday) {
            return "Today"
        } else if (difference < (oneday * 2)) {
            return "Yesterday"
        } else {
            let noteDateObject = df.dateFromString(noteDate)
            df.dateFormat = "MM/dd/yy"
            return df.stringFromDate(noteDateObject!)
        }
    }
    func setDate() -> String {
        df.dateFormat = "yyyy-MM-dd HH:mm:ss"
        return df.stringFromDate(NSDate())
    }
}
//
//  DateTimeManipulation.swift
//  Noted
//
//  Created by Michael Andrew Auer on 3/19/16.
//  Copyright © 2016 Usonia LLC. All rights reserved.
//

import Foundation

struct DateTime {
    
    let df: NSDateFormatter = NSDateFormatter()
    
    init() {
        df.dateFormat = "yyyy-MM-dd HH:mm:ss"
    }
    func fmtDate(noteDate: String) -> String {
        if (noteDate == "") {
            return ""
        }
        
        let noteNSD: NSDate = df.dateFromString(noteDate)!
        let difference = -(noteNSD.timeIntervalSinceNow)
        let oneday: Double = 86400
        
        if (difference < oneday) {
            return "Today"
        } else if (difference < (oneday * 2)) {
            return "Yesterday"
        } else {
            df.dateFormat = "mm/dd/yy"
            return df.stringFromDate(df.dateFromString(noteDate)!)
        }
    }
    func setDate() -> String {
        df.dateFormat = "yyyy-MM-dd HH:mm:ss"
        return df.stringFromDate(NSDate())
    }
}
--- 
+++ 
@@ -29,8 +29,9 @@
         } else if (difference < (oneday * 2)) {
             return "Yesterday"
         } else {
-            df.dateFormat = "mm/dd/yy"
-            return df.stringFromDate(df.dateFromString(noteDate)!)
+            let noteDateObject = df.dateFromString(noteDate)
+            df.dateFormat = "MM/dd/yy"
+            return df.stringFromDate(noteDateObject!)
         }
     }
     func setDate() -> String {
Fix date formatting on unwrap bug
