Created
December 23, 2011 22:14
-
-
Save durran/1515507 to your computer and use it in GitHub Desktop.
Customize Mongoid to persist times as integers +/- epoch.
This file contains 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
module Windows | |
class Time | |
include Mongoid::Fields::Serializable | |
def deserialize(time) | |
Time.at(time) | |
end | |
def serialize(time) | |
time.to_i | |
end | |
end | |
end | |
class Foo | |
include Mongoid::Document | |
field :time, type: Windows::Time | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You will see when you save, Mongoid will store in seconds pre or post epoch:
And when you query, Mongoid will convert as well: