模块: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。



13
14
15
# File 'lib/mongoid/extensions/time_with_zone.rb', line 13

def __mongoize_time__
  self
end

#_bson_to_iObject

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



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

def _bson_to_i
  return  if 定义?()

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

# mongoize时间

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

例子:

将对象 Mongoize。

date_time.mongoize

返回:

  • 时间

    该对象已mongo化。



24
25
26
# File 'lib/mongoid/extensions/time_with_zone.rb', line 24

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