模块:Mongoid::Extensions::TimeWithZone

定义于:
lib/mongoid/extensions/time_with_zone.rb

Overview

向 ActiveSupport::TimeWithZone 类添加类型转换行为。

在命名空间下定义

模块: 类方法

实例方法摘要折叠

实例方法详细信息

# __mongoize_time__ActiveSupport::TimeWithZone

将 ActiveSupport::TimeWithZone 转换为时间。

TimeWithZone 始终会 mongoize 为 TimeWithZone 实例(它们本身)。

返回:

  • ( ActiveSupport::TimeWithZone )

    self。



16
17
18
# File 'lib/mongoid/extensions/time_with_zone.rb', line 16

def __mongoize_time__
  self
end

#_bson_to_iObject

这段代码是从 bson-Ruby gem 中的 Time 类扩展复制的。 当最低BSON版本为5 + 时,应将其从此处删除。 请参阅jira.mongodb.org/browse/MONGOID-{2 5491



34
35
36
37
38
39
40
41
42
43
# File 'lib/mongoid/extensions/time_with_zone.rb', line 34

def _bson_to_i
  return  if 定义?()
  # JRuby #to_i 负时间戳向上取整的解决方法
  # 而不是向下 (https://github.com/jRuby/jRuby/issues/ 6104 )
  if BSON::environment.jRuby?
    (self - usec.to_r/1000000).to_i
  else
    to_i
  end
end

# mongoize时间

将对象从我们处理的Ruby类型转换为mongo友好类型。

例子:

将对象 Mongoize。

date_time.mongoize

返回:

  • 时间

    该对象已mongo化。



27
28
29
# File 'lib/mongoid/extensions/time_with_zone.rb', line 27

def mongoize
  ::ActiveSupport::TimeWithZone.mongoize(self)
end