getdate.y语法疑点
我试图了解 yyTimezone
在下面的代码中是如何计算的:
| 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);
}
我的理解是,假设时间戳是2011-01-02T10:15:20-04:00
;这意味着它比 UTC
晚 0400
小时。因此,要将其转换为 UTC
,您需要添加 0400
小时,它就会变成 2011-01-02T14:15:20
。我的理解正确吗?
我上面粘贴的代码块是如何实现的?
I am trying to understand how yyTimezone
is calculated in 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);
}
How I understand is, lets say the timestamp is 2011-01-02T10:15:20-04:00
; this means its 0400
hours behind UTC
. So to convert it into UTC
, you add 0400
hours to it and it becomes 2011-01-02T14:15:20
. Is my understanding correct?
How is that achieved in the codeblock I pasted above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输入将对偏移量进行编码,如
-0400
。其中的0400
部分将作为tUNUMBER
令牌返回(大概保存一个无符号值)。该标记符合语法规则,可以用作$3
。要获取值
400
的实际偏移量(以分钟为单位),您首先必须将其分成两半。小时部分可以通过$3 / 100
获取(即4
),分钟部分可以通过$3 % 100
获取(即4
)。 >0)。由于一小时有 60 分钟,因此您可以将小时乘以 60,然后加上分钟 ($3 % 100 + ($3 / 100) * 60
),这将得到值>240
。然后剩下的就是添加符号,并将其存储在yyTimezone
中。毕竟,
yyTimezone
将包含以分钟为单位的时区偏移量。The input would encode the offset like
-0400
. The0400
part of that would be returned as thetUNUMBER
token (presumably holding an unsigned value). This token is matched by the grammar rules, and can be used as$3
.To get the actual offset in minutes from the value
400
, you first have to split it up in two halves. The hours part can be obtained with$3 / 100
(ie.4
), and the minutes part with$3 % 100
(ie.0
). Since there are 60 minutes in an hour, you multiply the hours by 60, and add the minutes to that ($3 % 100 + ($3 / 100) * 60
), which would give the value240
. Then all that's left, is to add the sign, and store it inyyTimezone
.After all that,
yyTimezone
will contain the timezone offset in minutes.