mardi 19 avril 2016

Ruby on Rails 3 Timezone causing 1 hour difference

I have a job which runs every 10 min and fetches trips data. Trips have start time (depart time). The job sends mail notification to such trips which did not start at their depart time and have crossed 30 minutes i.e. a Trip was suppose to start at 10 AM and now at 10:30 AM if it still does not start then send mail notification to it. The trips depart time is in UTC. The client / application time is in Eastern time zone. The problem I am facing is the job fetches data and sends mail, but the mails are sent 1 hour late. I am not able to find the cause. Time.now shows UTC time, Time.zone.now shows EST time. Could this be related to timezone or the logic I am using to fetch 30 minutes difference. Suppose trips is to start at 8 AM. my job when will run at 8:30 AM, it will look for trips having

Model.where("departtime >  Time.now - 40.minutes and departtime <=  Time.now - 30.minutes")

This line will help to fetch trips before 30 min from current time. If a trips falls in this condition, I then check if a message is present for it in messages table (When trips starts, a message is sent). If no record found, then send mail. The time in messages table is also UTC. So as per the example the mail should go at 8:30 UTC and respective Eastern time zone. SO the mail goes correctly as per UTC, but the corresponding Eastern time is 1 hour late then the time it should actually have being sent. The mail goes at 9:30 in Eastern time.

Please let me know what am I missing.

Aucun commentaire:

Enregistrer un commentaire