我正在尝试进行夏令时转换。
我在“void IsDst(date){”中确定“日期”尺寸时遇到困难
我尝试过“void IsDst(datetime date){”
不确定它是如何工作的?
dstdata.htm
date = new DateTime(yr, mo-1, dy, hr24, mn, 0);
Textbox7.value = IsDst(日期);
dstdata.js
private void IsDst(日期){
if (日期.月份 < 2 || 日期.月份 > 10){
返回0;
}elseif (日期.月份 >= 2 && 月份 <= 10){
var aaa=0;
if (日期.月份==2){
var dstshr=2;
for (var Dys=1;dys<=25;dys++){
var dsts= new DateTime(yr, 2, Dys, dstshr, 0, 0);
if ((dsts.DayOfWeek==0) && (aaa==1)){
if (date.Date 2 && 月份 < 10){
返回1;
}
I am trying to do Daylight Savings Time conversion.
I am having difficulties dimensioning "date" in the "void IsDst(date){"
I have tried "void IsDst(datetime date){"
Not sure how it works?
dstdata.htm
date = new DateTime(yr, mo-1, dy, hr24, mn, 0);
Textbox7.value = IsDst(date);
dstdata.js
private void IsDst(date){
if (date.month < 2 || date.month > 10){
return 0;
}elseif (date.month >= 2 && month <= 10){
var aaa=0;
if (date.month==2){
var dstshr=2;
for (var dys=1;dys<=25;dys++){
var dsts= new DateTime(yr, 2, dys, dstshr, 0, 0);
if ((dsts.DayOfWeek==0) && (aaa==1)){
if (date.Date<dsts.Date){
return 0;
}else{
return 1;
}
}elseif ((dsts.DayOfWeek==0) && (aaa==0)){
aaa=1;
dstshr=3;
}
}
}
}elseif(date.month==10){
var bbb=0;
var dstehr=2;
for (var dye=1;dye<=25;dye++){
dste= new DateTime(yr, 10, dye, dstehr, 0, 0);
if ((dste.DayOfWeek==0) && (bbb==0)){
dste.hour=dste.hour+1;
bbb=1;
if ((date.Date<dste.Date){
return 0;
}else{
return 1;
}
}
}
}
}elseif (date.month > 2 && month < 10){
return 1;
}
发布评论
评论(2)
一个混乱(和问题)的案例。
方法 IsDst 似乎有一个 void 返回类型,其名称表明它返回一个布尔值,并且返回整数。
One case of confusion (and problems).
Method
IsDst
seems to have a void return type, has a name that suggests that it returns a boolean, and returns integer.该代码似乎不是 ECMAScript。逻辑看起来相当复杂,并且 block:
永远不会被输入,因为如果它为 true,它将已经被前一个 block: 捕获:
如果您试图根据主机设置确定 DST 在特定日期是否有效,那么您可以测试:
例如
上面假设如果 1 月 1 日和 7 月 1 日的偏移量不同,则该年观察到夏令时,并且这两个偏移量中的最小值为 DST 偏移量(请注意,ECMAScript 偏移量具有与约定相反的含义,即它们格林威治以西为 +ve,以东为 -ve)。然而,两个偏移量不同的事实并不一定意味着遵守夏令时(见下文)。
一旦针对 2023 年 11 月 5 日美国可能对永久夏令时的更改更新了实现:
因此对于 2023 年 11 月 5 日至 12 月 31 日, hasDST 和 inDST 将在本应为 false 时返回 true。对于年内改变偏移量的其他地方也会出现类似的错误。
鉴于特定位置的日期是否处于夏令时实际上无关紧要,重要的是偏移量,这两个函数的全部意义都是值得怀疑的。有很多地方根本没有夏令时。
爱尔兰不仅没有夏令时,而且还有相反的情况:夏季的标准时间 (IST) 是 UTC+1,然后在冬季时钟会调回 UTC+0 (GMT)。上面认为IST是夏令时,GMT是标准时间。
因此,最好将日期保存为不带时区的日期,将日期时间保存为 UTC,然后根据转换时已知的偏移规则计算出特定地点所需的偏移量。
The code doesn't appear to be ECMAScript. The logic appears quite convoluted and the block:
will never be entered because if it's true, it will already be caught by the previous block:
If you are trying to work out if DST is in force for a particular date based on the host settings, then you can test:
E.g.
The above assumes that if the offsets for 1 Jan and 1 Jul are different, then daylight saving is observed in that year and that the minimum of those two offsets is the DST offset (noting that ECMAScript offsets have the opposite sense to convention, i.e. they are +ve to the west and -ve to the east of Greenwich). However, the fact that the two offsets are different doesn't necessarily mean DST is observed (see below).
Once implementations are updated for the probable change to permanent DST in the US on 5 Nov 2023:
So for 5 Nov to 31 Dec 2023 both hasDST and inDST will return true when they should be false. Similar errors will occur for other places that change offsets during the year.
The whole point of both these functions is questionable given whether a date is in DST or not for a particular location really is irrelevant, what matters is the offset. There are many places that don't have DST at all.
Ireland not only doesn't have DST, it has the opposite: its standard time over summer (IST) is UTC+1, then clocks are set back to UTC+0 (GMT) over winter. The above thinks that IST is daylight saving and GMT is standard time.
Hence the reason why it's best to just save dates as dates without a timezone and datetimes as UTC, then work out the offset only as required for a specific place based on offset rules known at the time of conversion.