Class: DateTime

Inherits:
Object show all
Defined in:
lib/mongo_doc/ext/date_time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bson_create(bson_hash, options = nil) ⇒ Object



10
11
12
# File 'lib/mongo_doc/ext/date_time.rb', line 10

def self.bson_create(bson_hash, options = nil)
  DateTime.parse(*bson_hash.values_at('dt', 'sg'))
end

.cast_from_string(string) ⇒ Object



14
15
16
# File 'lib/mongo_doc/ext/date_time.rb', line 14

def self.cast_from_string(string)
  DateTime.parse(string) unless string.blank?
end

Instance Method Details

#to_bson(*args) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/mongo_doc/ext/date_time.rb', line 2

def to_bson(*args)
  {
    MongoDoc::BSON::CLASS_KEY => self.class.name,
    'dt' => strftime,
    'sg' => start
  }
end