1

User Timezone update with Daylight saving time

(edited by arsalanqayum332 06/03/2021 02:07:47)

Topic: User Timezone update with Daylight saving time

Hi there,

We are trying to update user timezone but could not figure our how does AND (&) and OR  (|) bit operator works when calculating with daylight saving time.

Example URL
https://sdk.wialon.com/wiki/en/sidebar/ … me/example

There are hexadecimal values given: -3600 and 0xf000ffff

-3600 & 0xf000ffff
-268373520

After converting hexadecimal values to binary and performing & bit operator we are getting different results.

Can you please give hints how this calculation is actually working.

Best Regards
Arsalan

2

User Timezone update with Daylight saving time

Re: User Timezone update with Daylight saving time

Hi Arsalan,

First it needs to perform negative value (-3600) to binary as signed value (32 bit), using two’s complement method, where we get invert result : 0 instead 1, 1 instead 0 , plus 1

After we get correct binary value, we can apply mask 0xf000ffff and operation & (and).
We get some binary value which is decimal signed value (negative)

So for this binary value we apply DST mask with operation & (OR) , if there is not DST - the mask = 0x8000000
Final binary value will be represented some decimal negative values, for example tz=-134155792

Here is converter https://www.exploringbinary.com/twos-co … converter/ can help to see how values are performed

Diana Cheley
Wialon Hosting Expert
Gurtam
3

User Timezone update with Daylight saving time

(edited by arsalanqayum332 10/03/2021 11:04:42)

Re: User Timezone update with Daylight saving time

Hi Diana,
Thank you for your response.

I understand a majority of what you explained, however I’m stuck on where I can find out what daylight saving time was selected when user saves Time Zone.

Here is example from beginning to end.

User selected timezone, International Date Line West: -43200

-43200 (32 bit) binary using two’s complement method = 11111111111111110101011101000000

We need to perform the operation with mask 0xf000ffff, which has binary equals to = 11110000000000001111111111111111

11111111111111110101011101000000 & 11110000000000001111111111111111 = -1111111111111010100011000000

-1111111111111010100011000000 = -268413120

And we are going to select daylight time saving United States, Canada: from second Sunday in March to first Sunday in November with mask value equals to 0x0A010000
   
-268413120 (32 bit) binary using two’s complement method equals to = 11110000000000000101011101000000

Daylight time saving mask 0x0A010000 binary is equals to =  1010000000010000000000000000

11110000000000000101011101000000 | 1010000000010000000000000000 = -101111111101010100011000000

-101111111101010100011000000 = -100575424

We are on track so far!

Now to reverse the saved settings.

-100575424  (32 bit) binary using two’s complement method = 11111010000000010101011101000000

We need to perform an operation with mask 0xffff, which has binary equals to = 1111111111111111

11111010000000010101011101000000 & 1111111111111111 = 101011101000000

101011101000000 = 22336

To find out what timezone user selected, we need to perform OR operation with mask 0xffff0000

22336 (32 bit) binary using two’s complement method equals to = 00000000000000000101011101000000

We need to perform | (OR) operation with mask 0xffff0000, which has binary equals to = 11111111111111110000000000000000

00000000000000000101011101000000  | 11111111111111110000000000000000 = -1010100011000000

-1010100011000000 = -43200

We successfully reversed timezone value -43200, International Date Line Wes.

But I cannot not understand how to reverse daylight time saving  United States, Canada: from second Sunday in March to first Sunday in November value during the process

Your hints and direction would be highly appreciated.

Thank you,
Arsalan

4

User Timezone update with Daylight saving time

Re: User Timezone update with Daylight saving time

arsalanqayum332 wrote:

But I could not understand how to reverse daylight time saving  United States, Canada: from second Sunday in March to first Sunday in November value during the process

Your hints and direction would be highly appreciated.

Thank you,
Arsalan .

Hi Arlasan,

When you apply Daylight time saving mask with value 0x0A010000, you just need to apply value = 0x08000000  which means there is not any DST settings.

Diana Cheley
Wialon Hosting Expert
Gurtam