parsing - How do I represent morning and midnight timings in ruby? -
i need store , retrieve restaurant timings in simple methods morning
, midnight
. doing is:
def morning time.new("6:30 am") end def midnight time.new("12:00 am") end
i can compare timings seems wrong way , don't know how read time values method like:
def open?(time) time >= morning && time <= midnight end
what right way this?
using chronic
gem able this:
def opens_at morning end def closes_at midnight end def open?(time) chronic.parse(time) >= morning && chronic.parse(time) < midnight end private def morning chronic.parse("6:30 am") end def midnight chronic.parse("midnight") end
this works comparisons
Comments
Post a Comment