Skip to content

Instantly share code, notes, and snippets.

@StephenOTT
Created March 26, 2015 05:10
Show Gist options
  • Save StephenOTT/fc49f278f094fade10bd to your computer and use it in GitHub Desktop.
Save StephenOTT/fc49f278f094fade10bd to your computer and use it in GitHub Desktop.
Date Conversion for MongoDB
Here is a way to deal with this issue:
def convertIssueDatesInMongo (issues)
issues.each do |y|
y["created_at"] = DateTime.strptime(y["created_at"], '%Y-%m-%dT%H:%M:%S%z').to_time.utc
y["updated_at"] = DateTime.strptime(y["updated_at"], '%Y-%m-%dT%H:%M:%S%z').to_time.utc
end
return issues
end
issues is a Array with a hash inside of it.
This example was from dealing with the Github API for the Issues API.
Note that "to_time" is only available starting in ruby ~1.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment