Timegap on heroku servers - heroku

I have a strange issue with the scheduler.
I'm sending a reporting that's always referring to the last day, however the reporting always refers to the day before that day. E.g. on the 2nd of January (time of writing this), it's the 31th of december (it has nothing to do with month / year change).
When I log in to the server, the times seem to be correct:
$ date
Do 2. Jan 08:33:48 UTC 2014
# via python:
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2014, 1, 2, 8, 33, 44, 650541)
# the func that calcs the previous day gives the correct day as well
>>> dates.getBeginningOfYesterday().strftime('%d.%m.%Y')
'01.01.2014'
So, basically I'm not able to reproduce the error, but the scheduler keeps sending with this timegap.

My guess is a local time offset causing you to span a day boundary incorrectly. The examples you show are in UTC, but if you're using a localized timestamp for calculations there could easily be a 5+ hour time offset, causing you to be a day earlier.

Related

Google Spreadsheet time between date - hour calculation

I am at a loss, i looked around the internet and stackoverflow but every so called solution is giving either errors or plainly don't work.
I have the following setup.
4 fields (setup in date dd-mm-yyyy, hour hh:mm:ss) seconds are not important.
start date : 7-1-2020
start hour : 23:30:00
end date : 8-1-2020
end hour : 03:50:00
What i want to happen is to calculate the diffrence in 'hours, minutes' between the end and the start date, hour. But when I calculate and change the end date to lets say 09-01-2020 it does not count the extra 24h at all.
Use Text format:
=text(A3-A1+A4-A2,"[H]:MM")
You need to format the time difference as a duration using the custom format
[h]:mm
for hours and minutes
or
[h]
for whole hours.
There are some good notes on how it works in Excel here and as far as I can tell from testing it Google Sheets is the same.
Alternatively, if I read your question as wanting to drop the minutes and seconds from the times before doing the calculation, you could use
=(B3-B1)*24+hour(B4)-hour(B2)
and just format the result as a normal number.
After alot of fiddeling and this post i came to the conclusion that the main issue was not laying within the mathematical but within the format of the cell.
By default all time values in sheets are 24h max.
So the basic formula =start - end
The time format needed should be
more date time format
elapsed hours : elapsed minutes
apply
Now you should see the correct elapsed hours and minutes

Comparing Date In Parse Cloud Code

I have some problem with comparing to dates in Parse Cloud Code using moments.js
I'm sending new ETA of a client and compare it with the ETA saved in server.
The time in client looks fine, but when i send it to Cloud Code i changed by 2 hours.
Here is the log of my Cloud Code:
Set ETA at first time:
Input: {"orderID":"S9Aztq5Hky","userETA":"20:27"}
ETA Update Log (The comparison made here):
I2016-01-10T18:15:03.913Z]User New ETA: Sunday, January 10th 2016, 6:15:03 pm GMT+0000
I2016-01-10T18:15:05.873Z]User Current ETA Value: Sunday, January 10th 2016, 8:27:46 pm GMT+0000
What do I miss?
Why does the time change?
Thanks.

Run a job every other monday

I would like to use Heroku scheduler to run every OTHER Monday. However, it only runs hourly, daily, every 10 minutes.
I read this...
How can I schedule a 'weekly' job on Heroku?
However, I'm not sure what code can be used. I think I can figure out every Monday, but not every OTHER Monday.
thanks
As you get more complicated, I'd recommend checking out scheduling gems. If you want to stick to vanilla Ruby, look at a combination of monday? and cweek, which tells you the week number in the current year. Run your job on Mondays in even-numbered weeks.
date = Date.today
date.monday? && date.cweek.even?
Note that cweek can return 53, since 365 isn't divisible by 7 and it has to handle that last, partial week. The new year's first week will be 1 (it doesn't count from 0), so you have to either skip a week or do two runs in a row when Monday falls in week 53.

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).

Resources