Getdate.y grammatical doubts

http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/usr.bin/tar/Attic/getdate.y?rev=1.9.12.1;content-type=text%2Fplain;hideattic= 0

I am trying to understand how yyTimezone computed in the code below:

 | bare_time '+' tUNUMBER { /* "7:14+0700" */ yyDSTmode = DSToff; yyTimezone = - ($3 % 100 + ($3 / 100) * 60); } | bare_time '-' tUNUMBER { /* "19:14:12-0530" */ yyDSTmode = DSToff; yyTimezone = + ($3 % 100 + ($3 / 100) * 60); } 

As I understand it, let's say that the timestamp is 2011-01-02T10:15:20-04:00 ; this means 0400 hours behind UTC . To convert it to UTC , you add 0400 hours to it, and it becomes 2011-01-02T14:15:20 . Do I understand correctly?

How is this achieved in the code block that I inserted above?

+1
source share
1 answer

The entrance will be encoded as an offset -0400 . Part 0400 will be returned as a tUNUMBER token (supposedly containing an unsigned value). This token complies with the grammar rules and can be used as $3 .

To get the actual offset in minutes from a value of 400 , you first need to split it into two halves. The hourly part can be obtained using $3 / 100 (i.e. 4 ), and part of the minutes with $3 % 100 (i.e. 0 ). Since there are 60 minutes per hour, you multiply the hours by 60 and add minutes to this ( $3 % 100 + ($3 / 100) * 60 ), which gives a value of 240 . Then all that remains is to add the character and save it in yyTimezone .

After that, yyTimezone will contain the time zone offset in minutes.

+3
source

Source: https://habr.com/ru/post/895780/


All Articles