Can using Chronic impair you sense of time?

Posted by Trip on Stack Overflow See other posts from Stack Overflow or by Trip
Published on 2010-05-12T18:47:55Z Indexed on 2010/05/12 18:54 UTC
Read the original article Hit count: 185

Filed under:
|

Haha..

I'm using Chronic to parse the time users add in the Calendar. Where the code works and implements the right time, the end result is that, IF a user adds a time, then it has no date, and because it has no date, it will not show in results. Any ideas?

def set_dates

unless self.natural_date.blank? || Chronic.parse(self.natural_date).blank?

  # check if we are dealing with a date or a date + time

  if time_provided?(self.natural_date)

    self.date = nil

    self.time = Chronic.parse(self.natural_date)

  else

    self.date = Chronic.parse(self.natural_date).to_date

    self.time = nil

  end

end

unless self.natural_end_date.blank? || Chronic.parse(self.natural_end_date).blank?

  # check if we are dealing with a date or a date + time

  if time_provided?(self.natural_end_date)

    self.end_date = nil

    self.end_time = Chronic.parse(self.natural_end_date)

  else

    self.end_date = Chronic.parse(self.natural_end_date).to_date

    self.end_time = nil

  end

end

end

© Stack Overflow or respective owner

Related posts about chronic

Related posts about ruby-on-rails