//
//  NSDateExtensions.swift
//  Heimdall
//
//  Created by Felix Jendrusch on 2/10/15.
//  Copyright (c) 2015 B264 GmbH. All rights reserved.
//

import Argo
import Runes

extension NSDate: Comparable {}

public func == (lhs: NSDate, rhs: NSDate) -> Bool {
    return lhs.isEqualToDate(rhs)
}

public func <= (lhs: NSDate, rhs: NSDate) -> Bool {
    return lhs < rhs || lhs == rhs
}

public func >= (lhs: NSDate, rhs: NSDate) -> Bool {
    return rhs <= lhs
}

public func < (lhs: NSDate, rhs: NSDate) -> Bool {
    return lhs.compare(rhs) == NSComparisonResult.OrderedAscending
}

public func > (lhs: NSDate, rhs: NSDate) -> Bool {
    return rhs < lhs
}

extension NSDate: JSONDecodable {
    public class func decode(json: JSONValue) -> NSDate? {
        if let timeIntervalSinceNow = json.value() as NSTimeInterval? {
            return NSDate(timeIntervalSinceNow: timeIntervalSinceNow)
        } else {
            return nil
        }
    }
}

//
//  NSDateExtensions.swift
//  Heimdall
//
//  Created by Felix Jendrusch on 2/10/15.
//  Copyright (c) 2015 B264 GmbH. All rights reserved.
//

import Foundation

extension NSDate: Comparable {}

public func == (lhs: NSDate, rhs: NSDate) -> Bool {
    return lhs.isEqualToDate(rhs)
}

public func <= (lhs: NSDate, rhs: NSDate) -> Bool {
    return lhs < rhs || lhs == rhs
}

public func >= (lhs: NSDate, rhs: NSDate) -> Bool {
    return rhs <= lhs
}

public func < (lhs: NSDate, rhs: NSDate) -> Bool {
    return lhs.compare(rhs) == NSComparisonResult.OrderedAscending
}

public func > (lhs: NSDate, rhs: NSDate) -> Bool {
    return rhs < lhs
}

--- 
+++ 
@@ -6,7 +6,8 @@
 //  Copyright (c) 2015 B264 GmbH. All rights reserved.
 //
 
-import Foundation
+import Argo
+import Runes
 
 extension NSDate: Comparable {}
 
@@ -29,3 +30,13 @@
 public func > (lhs: NSDate, rhs: NSDate) -> Bool {
     return rhs < lhs
 }
+
+extension NSDate: JSONDecodable {
+    public class func decode(json: JSONValue) -> NSDate? {
+        if let timeIntervalSinceNow = json.value() as NSTimeInterval? {
+            return NSDate(timeIntervalSinceNow: timeIntervalSinceNow)
+        } else {
+            return nil
+        }
+    }
+}
Make NSDate conform to JSONDecodable
