How to interpret RFC3339 UTC timestamp - time

How should I interpret all aspects of the following timestamps? Where is the time based and how do timezones apply?
2015-11-15T14:45:28Z
2015-11-15T14:45:28.9694Z
2015-11-15T14:45:28.969412345Z
Below is my thoughts...
Date: 2015-11-15
???: T
Hours: 14
Minutes: 45
Seconds: 28 OR 28.9694 OR 28.969412345
???: Z

Most of your values are attributed correctly. The date portion (2015-11-15) is in the order YYYY-MM-DD, time in HH:MM:SS.ffff.
T indicates the start of the time portion of the date time.
Z indicates the time zone is UTC. Next to Z, you could have a format like Z+02:00, which indicates the time zone is UTC + 2 hours.

Related

BigQuery Convert Int to Timestamp and Add to Another Timestamp

I'm not sure how to approach this issue. I used this statement below to convert an integer into a timestamp. The goal is to convert "duration_minutes from an integer to a timestamp, add the hours, minutes and seconds to the startTime.
TIMESTAMP_SECONDS(s.duration_minutes)
output:
1970-01-01 00:03:05 UTC
startTime
2016-07-13 00:00:00 UTC ```

Issue with checking time ranges overlapping

Issue:
overlaps? method doesn't return expect value.
(start_on.to_i..end_on.to_i).overlaps?(ti.start_time.to_i..ti.end_time.to_i)
It returns false, but should be true.
start_on: 2016-08-19 11:00:00 +0200
end_on: 2016-08-19 12:00:00 +0200
ti.start_time: 2000-01-01 08:00:00 UTC
ti.end_time: 2000-01-01 12:00:00 UTC
Hours like 11:00-12:00 overlaps with 08:00-12:00. Why method returns false? All columns in database are type of time. Current date is caused by Time.parse method.
I suppose that problem is with date second part of times have 2000 year, but first 2016. Anyone know how to fix it?
You can try by getting only time by this strftime("%H:%M").
Result:
(start_on.strftime("%H:%M")..end_on.strftime("%H:%M")).overlaps?(ti.start_time.strftime("%H:%M")..ti.end_time.strftime("%H:%M"))

Lua UTC time inconsistencies

Lua 5.1 doc says:
If format starts with '!', then the date is formatted in Coordinated
Universal Time.
If format is %c, !'s behavior seems correct
local date_1 = os.date("!%c")
local date_2 = os.date("%c")
print("utc date: "..date_1)
print("not utc date: "..date_2)
If format is *t, !'s behavior seems swapped
local time_1 = os.time(os.date("!*t"))
local time_2 = os.time(os.date("*t"))
print("should be utc time, but is not: "..time_1) -- this should be UTC, and is not
print("should not be utc time, but is: "..time_2) -- this should not be UTC, but is
Dates are tested with: http://www.epochconverter.com/
Why is that?
The table returned by os.date("!*t") and os.date("*t") is correct. I'm printing only the hour field. Note that they are consistent with %c format:
local date_1 = os.date("!%c")
local date_2 = os.date("%c")
print("utc date: "..date_1)
print("not utc date: "..date_2)
print("utc date hour: " .. os.date("!*t").hour)
print("not utc date hour: " .. os.date("*t").hour)
Output on my machine (China Standard Time, UTC+08:00):
utc date: 02/06/15 02:02:29
not utc date: 02/06/15 10:02:29
utc date hour: 2
not utc date hour: 10
However, os.time takes the table, assuming it's the local time, and returns the epoch. So, the local time is converted to the real epoch, but the utc time is not.
print(os.time{year=1970, month=1, day=1, hour=8})
outputs 0 on my machine.

format subtract dates result to "hh:mm:ss"

I need to format subtract 2 long date time result to "hh.mm.ss"
open date closed date subtracted
01/01/2012 16:04 04/01/2012 17:07 3.01:02:58
02/01/2012 08:52 02/01/2012 17:03 08:10:27
using
closeddate.subtract(opendate)
return result in format D.hh:mm:ss
and using
DateDiff("h", OpenDate, closeDate)
return hours only (no minutes or seconds)
Also tried
closeddate.subtract(opendate).tostring("hh:mm:ss")
not working
as many Microsoft forums answered there is no way to do that
so i used
DateDiff("s", OpenDate, closeDate)
and passed result to helper function return calculated time in format hh:mm:ss

How do I calculate the offset, in hours, of a given timezone from UTC in ruby?

I need to calculate the offset, in hours, of a given timezone from UTC in Ruby. This line of code had been working for me, or so I thought:
offset_in_hours = (TZInfo::Timezone.get(self.timezone).current_period.offset.utc_offset).to_f / 3600.0
But, it turns out that was returning to me the Standard Offset, not the DST offset. So for example, assume
self.timezone = "America/New_York"
If I run the above line, offset_in_hours = -5, not -4 as it should, given that the date today is April 1, 2012.
Can anyone advise me how to calculate offset_in_hours from UTC given a valid string TimeZone in Ruby that accounts for both standard time and daylight savings?
Thanks!
Update
Here is some output from IRB. Note that New York is 4 hours behind UTC, not 5, because of daylight savings:
>> require 'tzinfo'
=> false
>> timezone = "America/New_York"
=> "America/New_York"
>> offset_in_hours = TZInfo::Timezone.get(timezone).current_period.utc_offset / (60*60)
=> -5
>>
This suggests that there is a bug in TZInfo or it is not dst-aware
Update 2
Per joelparkerhender's comments, the bug in the above code is that I was using utc_offset, not utc_total_offset.
Thus, per my original question, the correct line of code is:
offset_in_hours = (TZInfo::Timezone.get(self.timezone).current_period.offset.utc_total_offset).to_f / 3600.0
Yes, use TZInfo like this:
require 'tzinfo'
tz = TZInfo::Timezone.get('America/Los_Angeles')
To get the current period:
current = tz.current_period
To find out if daylight savings time is active:
current.dst?
#=> true
To get the base offset of the timezone from UTC in seconds:
current.utc_offset
#=> -28800 which is -8 hours; this does NOT include daylight savings
To get the daylight savings offset from standard time:
current.std_offset
#=> 3600 which is 1 hour; this is because right now we're in daylight savings
To get the total offset from UTC:
current.utc_total_offset
#=> -25200 which is -7 hours
The total offset from UTC is equal to utc_offset + std_offset.
This is the offset from the local time where daylight savings is in effect, in seconds.

Resources