NetEaseWD / NEJ

跨平台WEB前端开发框架
Other
55 stars 13 forks source link

日历组件跨年BUG #10

Closed cloudcome closed 9 years ago

cloudcome commented 9 years ago

文件src/util/calendar 修改前: p 修改后:

_pro.__doSyncDateShow = (function(){
        var _days = [31,28,31,30,31,30,31,31,30,31,30,31];
        var _isLeap = function(_year){
            return !(_year%400)||!(_year%4)&&!!(_year%100);
        };
        var _getMonthDay = function(_year,_month){
            return _month==2&&_isLeap(_year)?29:_days[_month-1];
        };
        return function(){
            var _year  = this.__year,
                _month = this.__month,
                _date  = new Date(_year,_month-1, 1),
                // 上一个月
                datePrev = new Date(_year, _month-2, 1),
               // 下一个月
                dateNext = new Date(_year, _month, 1),
                _beg = ((7+_date.getDay())-this.__offset)%7,
                _end = Math.min(this.__list.length,
                      _beg+_getMonthDay(_year,_month));
            // sync year and month
            if (!!this.__nyear)
                this.__nyear.innerText = this.__year;
            if (!!this.__nmonth)
                this.__nmonth.innerText = this.__month;
            // offset with limit
            for(var i=_beg,_node;i<_end;i++){
                _node = this.__list[i];
                this.__doSaveDateInfo(
                      _node,_year,_month,i-_beg+1);
                _e._$delClassName(_node,this.__extended);
            }
            // 0 -> begin
            if (_beg>0){
                //_date.setMonth(_month-2||0);
                _year  = datePrev.getFullYear();
                var _monthTemp = datePrev.getMonth()+1;
                var _limit = _getMonthDay(_year,_monthTemp);
                for(var i=_beg-1,_node;i>=0;i--){
                    _node = this.__list[i];
                    this.__doSaveDateInfo(
                          _node,_year,_monthTemp,_limit--);
                    _e._$addClassName(_node,this.__extended);
                }
            }
            // end -> length
            var _length = this.__list.length;
            if (_end<_length-1){
                //_date.setMonth(_month);
                _year  = dateNext.getFullYear();
                _month = dateNext.getMonth()+1;
                for(var i=_end,k=1;i<_length;i++){
                    _node = this.__list[i];
                    this.__doSaveDateInfo(
                          _node,_year,_month,k++);
                    _e._$addClassName(_node,this.__extended);
                }
            }
        };
    })();
genify commented 9 years ago

非常感谢您的反馈,此bug已在master的commit 93ea6e6594dc3df7e409d0061b7bed341d6eb3e2 和20140731的branch中修正,bug主要原因是计算过程中公用了同一个date对象导致

genify commented 8 years ago

This issue was moved to NEYouFan/nej-framework#10