Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Time::BSON_TYPE for Date and DateTime instances #15

Merged
merged 3 commits into from
Feb 18, 2014

Conversation

mdsell
Copy link
Contributor

@mdsell mdsell commented Feb 16, 2014

This pull request allows Date and DateTime objects to be serialised as BSON when inside Hash and Array objects.

Currently, the following produces a NoMethodError:

{ date: Date.today }.to_bson

Instances of Date (and by extension DateTime) do not respond to bson_type, but do convert to Time objects when serialised directly. Mapping these instances as part of an Array or Hash does require these to respond to bson_type, and so to fix this, I've defined a bson_type method on Date (inherited by DateTime) which returns the value of Time::BSON_TYPE.

This is, as you might imagine, largely an itch-scratching PR. If this logic is better suited to my application, let me know!

durran added a commit that referenced this pull request Feb 18, 2014
Return Time::BSON_TYPE for Date and DateTime instances
@durran durran merged commit 22ddc2c into mongodb:master Feb 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants