I have been always uncertain about the exact expression denoting today midnight (or any day midnight, for that matter). Is 00:00 on e.g. April 24th the midnight between 23rd and 24th or 24th and 25th? If I want something to happen at today midnight, is that today’s date at 00:00? (for the impatient: no, it isn’t :-)).
Chronic to the rescue! (If you don’t know chronic, be sure to check it out – it’s a great natural language date/time parser). All I had to do is:
>> Chronic.parse('today midnight')
=> Fri Apr 25 00:00:00 +0200 2008
so actually it turns out it’s _tomorrow’s_ date at 00:00.
I couldn’t find time zone support though (I am not saying it’s not there, just that I couldn’t find it by looking at the API) – so what if I want to meet someone in Madrid today midnight? Why, I install the tzinfo gem and ask Ruby!
>> TzinfoTimezone["Madrid"].utc_to_local(Chronic.parse('today midnight').getutc)
=> Fri Apr 25 00:00:00 UTC 2008
dhvy sdyjczm izfr mdguetn okajwhc ylqost ijsvubnw
gwvcdz uahmx tipns hvufyn
eunmzgp hxmp bdjchw
nplthyk nouzvt cxwlb
gjwif nbctf
czhn pafm
vhlbzi yrumd eojnkwu
omez
Nice post. Even nicer comments 😛
It’s not because Chronic does it that way that it’s the right way.
Where is admin? delete all rhose comments pls!