今天客户报了一个日历的错误,仔细check了一下发现10月最后一个周日正好是法国夏令时/冬令时的切换时间,查了资料发现每个地区切换令时有的在三月有的在四月,于是写了以下判断~
来吧,马上就fixed issue啦~
代码
//判断当天是否是夏令时/冬令时时间切换天
getNextdayfromDay(date){
console.log('令时 date:' + date) //今天在切换
let d1 = date;
let d2 = new Date((date / 1000 + 86400) * 1000); //添加了一天
if (d1.getTimezoneOffset() < d2.getTimezoneOffset()){
console.log('今天在切换冬令时,需要多加一小时时间') //今天在切换
return d2 = new Date((date / 1000 + 86400 + 3600) * 1000);
}else if(d1.getTimezoneOffset() > d2.getTimezoneOffset()){
console.log('今天在切换夏令时') //今天在切换
return d2;
}else{
console.log('非今天在切换夏令时/非夏令时') //非今天在切换
return d2;
}
}