开发者

Best way to manage date objects?

I have some date objects that are Date of the Date class, and others that are Time.

The trouble is is that when I parse them to load them chronologically, they list first as the Times, followed by the Dates.

This is the code that loads them :

  query.any_of do |any_of|
    any_of.with(:date).greater_than((params[:current_date] || DateTime.now))
    any_of.with(:end_date).greater_than((params[:current_date] || DateTime.now))
    any_of.with(:time).greater_than((params[:c开发者_JAVA技巧urrent_date] || DateTime.now))
  end

Is there a way to combine both dates and times as one universal object to compare them? Ideally, it would be converting the Date Objects to Time since Time objects can hold dates and time.


def universal_time
  if self.date != nil
    self.date.to_time
  else
    self.time
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜