Heroku Scheduler timezone? - heroku

What's the Heroku timezone for Scheduler? It says "UTC" but I'm not sure if that's correct. My tasks are starting at the wrong time despite converting the timezone correctly.
Thoughts?

This question's a bit old, but yes, Heroku Scheduler definitely uses UTC even if you specify a timezone in your app. I tested it with this code:
task :send_test_email => :environment do
if Date.today.strftime("%A").downcase == 'monday'
UserMailer.send_test_email(Time.now.strftime("%Z")).deliver
end
end
I'm in Pacific time zone. I set Heroku Scheduler to run this every 10 minutes, and this email was able to send on Sunday night PST, which is Monday in UTC time. Also, the string I passed to the mailer,Time.now.strftime("%Z"), is set as the subject of the email which indeed read, "UTC"
One potential source of confusion is Daylight Saving Time. For example, UTC is always 8 hours ahead of Pacific Standard Time (PST - used for winter months), and 7 hours ahead of Pacific Daylight Time (PDT - used for summer months). So if your tasks are off by an hour, it could be you measured from the wrong UTC zone.

Related

Ruby - Get timezone offset from latitude and longitude for specific date and time

I am using the timezone gem to obtain the time zone from latitude and longitude. I need the time zone for some solar calculations. The API I use requires the timezone offset (without the daylight). For example now (2021/10/12 12:37) in UK with BST time the timezone offset for the API would be zero. With timezone though I would get 3600
tz = Timezone.lookup(51.51, 0.1)
=> #<Timezone::Zone name: "Europe/London">
tz.utc_offset
=> 3600
That's easy. I can check for daylight saving and correct.
(tz.dst?) ? (tz.utc_offset) : (tz.utc_offset - 3600)
I can do the same for another time (I do all the calculations in 2010) as long as it is in my locale timezone.
If I try, say, Melbourne, I am not able to create a time in that location and check the daylight saving. I am sure I am doing something wrong. Am I overthinking it?
For example:
tz = Timezone.lookup(-37.814, 145)
=> #<Timezone::Zone name: "Australia/Melbourne">
tz.utc_offset
=> 39600 ((10 + 1)h)
This is now (2021/10/12 12:37), but for my API to work this should be 10 because daylight should not be included.
My idea was to take a reference time, 2010/01/01 01:00 and make all the calculations for that time. The problem is that I don't know how I can create a time in a specific time zone and check whether that time is a daylight time.
I have tried
reftime = tz.time(Time.new(2010,1,1,1,0))
but if do
reftime = tz.time(Time.new(2010,1,1,1,0))
reftime.dst?
I get false, but it should be true.
How can I check whether a specific date in a specific location is in daylight saving mode?
Melbourne has started daylight saving at 2021-10-03 03:00:00. So it's using AEDT but not AEST.

How to get rid of reminder time issue in slack?

I am currently using slack, it’s a great team work tool. I have one issue though: when I create a remind say, /remind me “abc” at night, it sets the reminding time as 3pm. but this is not night, i would like to have 6pm, or better I can set it myself (i.e., set tonight as 6pm). How can I achieve this? - btw, i live in US west coast
You can use the time itself or a relative time:
/remind me "abc" at 6pm CST
/remind me "123" tomorrow night at 8pm CST
/remind me "youandme" 5 hours from now
You can also set your timezone data by exploring the /tz command
You can set it on the account level by following the instructions here.

How to get user hour of the week in Ruby

I want to get the current hour of the week in which day starts from Sunday.
Consider current time is
Time.now
=> 2014-10-29 12:09:23PM +0530
The result should be : 84
Explanation:
Sunday - 24 hours
Monday - 24 hours
Tuesday - 24hours
Wednesday - 12 hours
Total: 84
How can get the user hour of the week. Is there any method available in Ruby ? Or how to do it without Ruby method.
You can get the day of the week and hour of the day using Time#wday and Time#hour.
Time.now.wday
#=> 3
Time.now.hour
#=> 14
The rest is basic mathematics.
Even though I upvoted Yu Hao, I must say it's not a good approach if you want to pay attention to the concerns Jon Skeet raised. To that end, here's another approach:
(Time.now - (Date.today - Date.today.wday).to_time) / 3600
Date.today is, well, today. If you subtract the number of days since the week started, you get Sunday. Convert it to Time and it's the midnight when Sunday began. Subtraction gives you number of seconds between then and now. Divide by 3600 (and optionally round) to get number of hours. The DST details should be transparently handled by Time#-.
EDIT: Timezones... Run this before:
ENV['TZ']='EST5EDT'
(be sure to reset it back to what it used to be afterwards, in case anyone else needs to know time and didn't count on you switching timezones.) You can also use "America/New_York" instead. See tz list for details.

From string to different time zone not working in ruby

I have field in my table as "start_time" as string. E.g Value is "2014-02-07T02:00:00Z". This is provided by API.
We want to show this time as per the client time zone (May EST, Central, IST, Pacific time). For testing In my system I set time zone as (Estern Time (US&Canada))
I tried
start_at = "2014-02-07T02:00:00Z"
start_time = Time.parse(start_at.chop!)
gm_start_time = Time.gm(start_time.strftime('%Y'), start_time.strftime('%b'), start_time.strftime('%d').to_i, start_time.strftime('%H'), start_time.strftime('%M'), start_time.strftime('%S'))
event_start_time = gm_start_time.localtime.strftime('%m/%d/%Y %H:%M')
Result as:
2014-02-07 02:00:00 -0500 ==> start_time
2014-02-06 21:00:00 -0500 ==> gm_start_time
"02/06/2014 21:00" ==> event_start_time
Here I am trying is
convert the string to Time object
Converting that time to GMT
From GMT trying to find equivalent "loca ltime"
If central time is 2014-02-07T02:00:00Z, then local time should 2014-02-07T03:00:00Z
Why I am getting Feb 6th 21 hours. This is -5 hours from expected result. My timezone also -5 hours.
(Time is 24 hours format)
Anyone have any idea on what I am doing wrong?
I think you have some issues with understanding how to handle the time zones. The Z letter at the end of the timestamp indicates that the time is UTC, so apparently your API provides you the time in UTC. When you remove it by using chop! (note that you could simply use chop anyway), Ruby cannot tell anymore what the time zone is, so it's going to use your local time zone by default (I live in UTC+08:00):
1.9.3-p484 :006 > Time.parse("2014-02-07T02:00:00Z")
=> 2014-02-07 02:00:00 UTC
1.9.3-p484 :007 > Time.parse("2014-02-07T02:00:00")
=> 2014-02-07 02:00:00 +0800
Using Time.gm then becomes unnecessary since you already have the time in UTC (assuming the API always sends you timestamps in UTC).
Also, what you are exactly trying to achieve is a bit confusing because you have at least one typo in your post (unless you're trying to obtain a local time in Europe).

TimeZoneInfo Class and Daylight saving time

I am trying to get the Timezone of the device (windows phone). I used this class and the property BaseUtcOffset. I live In Jordan, and it was suppose to give me +3 hours, but instead it gave me +2. i think its the daylight saving time, but i have no idea how to use it, any ideas?
var x = TimeZoneInfo.Local.BaseUtcOffset; // x.Hours = 2
the correct timezone from timeanddate.com
You should use GetUtcOffset().
The BaseUtcOffset property returns the difference between UTC and the time zone's standard time; the GetUtcOffset method returns the difference between UTC and the time zone's time at a particular point in time.
That's the right response. The timezone is 2 hours ahead of UTC. Local time is 3 hours ahead of UTC.
You might want to look at GetUtcOffset() or IsDaylightSavingsTime().

Resources