Created
October 25, 2012 23:22
-
-
Save davidandrzej/3956097 to your computer and use it in GitHub Desktop.
Simple protocol / record example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defprotocol Dateable | |
| "Convertible to a Java Date" | |
| (to-date [this] "Convert to Java Date")) | |
| (defrecord TimeMs [timeInMs] | |
| Dateable | |
| (to-date [this] (new Date (long (:timeInMs this))))) | |
| (defrecord TimeOffset [offsetString] | |
| Dateable | |
| (to-date [this] | |
| (new Date (- (System/currentTimeMillis) | |
| (parse-offset-string offsetString))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment