Epoch timezoneoffsetat error?

malcfreem

Member
Licensed User
Longtime User
Hi. Could some on please explain why datetime.getoffsetat returns an offset of 1 when it surely should be zero?

My tablet is currently on GMT +1due to daylight saving time.

My actual issue is this:
I have built an app which inserts sports fixture dates and start times into the default calendar. The app parses both the fixtures date/time and the epoch date time. It subtracts one from the other to obtain the start time for the calendar entry. This is consistently one hour later than the actual start time.

I have changed the tablet date so that the timezoneoffset is zero, but that makes no difference

Any help greatly appreciated

Malcolm
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Hi. Could some on please explain why datetime.getoffsetat returns an offset of 1 when it surely should be zero?

My tablet is currently on GMT +1due to daylight saving time.
Can you post the relevant code and the device selected time zone and DST settings?

You should use DateUtils for such date calculations.
 
Upvote 0

malcfreem

Member
Licensed User
Longtime User
Hi Erel. Have had to retype code onto tablet due to net connection issues, but it goes:-

Dim UTC1 as long
Dim X as Int
Datetime.DateFormat("dd/MM/yyyy hh:mm:ss")
UTC1=Datetime.dateparse("01/01/1970 00:00:01")
X=Datetime.GetTimeZoneOffsetAt(UTC1)

X is set to 1 (GMT + 1). I am in the UK where we are on GMT (GMT + 0) from Oct til April, then on DST (GMT + 1) for the rest of the year. 01/01/1970 should return an offset of 0?
 
Upvote 0

malcfreem

Member
Licensed User
Longtime User
2nd part of reply

Sorry Erel, the code to calculate the date and time of the calendar entry is:

(dat contains the fixture date in format dd/mm/yyyy eg 01/03/2014)
(tim contains the fixture time in the format hh/mm eg 15:00)

UTC_TS=DateTime.DateParse(dat & " " & tim & ":00") - DateTime.DateParse("01/01/1970 00:00:00")

My development PC and tablet are on GMT+1, as is my Google calendar (all correct).

When I inspect the Calendar, the event is there at 16:00 (not 15:00)

Am I being thick?

Malcolm
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

malcfreem

Member
Licensed User
Longtime User
epoch

Hi Erel.

BST (British Summer Time-GMT+1) only applies for part of 1970 (April-Oct). The rest of the year was GMT+0, as itwas for the example Igave.

However, now I know arithmetic cannot be relied upon, I guess I should try your suggestion of DateUtils.SetDateAndTime.

Thanks for this - I didn't know the function existed and it looks much easier.

Malcolm
 
Upvote 0

malcfreem

Member
Licensed User
Longtime User
epoch apology

Well blige me! You are totally correct about 1970-I apologise. The government apparently experimented in 1970!


Malcolm
 
Upvote 0
Top