Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby日期时间比较问题_Ruby_Datetime - Fatal编程技术网

Ruby日期时间比较问题

Ruby日期时间比较问题,ruby,datetime,Ruby,Datetime,我正在为一个模型实现一个验证方法,该方法检查过期日期是否在发布日期之前。我试过这个 def valid_date_interval if self.expired_at && self.published_at errors.add(:published_at, I18n.t('ubiquo.highlight.error_invalid_interval')) if self.expired_at <= self.published_at end end

我正在为一个模型实现一个验证方法,该方法检查过期日期是否在发布日期之前。我试过这个

def valid_date_interval
  if self.expired_at && self.published_at
    errors.add(:published_at, I18n.t('ubiquo.highlight.error_invalid_interval')) if self.expired_at <= self.published_at
  end
end
def有效日期间隔
如果self.expired\u在&&self.published\u在

如果self.expired\u在可能self.expired\u在.nsec不等于self.expired\u在.nsec,则添加错误(:published\u at,I18n.t('ubiquo.highlight.error\u invalid\u interval'))。(nsec返回纳秒)。请参阅可能的重复项。你可以试试这个不,问题完全不同。。。
(rdb:1) p self.published_at.to_i == self.expired_at.to_i
true
(rdb:1) p self.published_at.to_i == self.expired_at.to_i + 1
false
(rdb:1) p self.published_at == self.expired_at
false
(rdb:1) p self
#<Highlight id: nil, title: "MyString", published_at: "2011-06-02 10:22:05", expired_at: "2011-06-02 10:22:05", created_at: nil, updated_at: nil, program_id: 827572094>