Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

双日历range设置BUG #74

Closed
nuintun opened this issue Apr 2, 2015 · 1 comment
Closed

双日历range设置BUG #74

nuintun opened this issue Apr 2, 2015 · 1 comment

Comments

@nuintun
Copy link

nuintun commented Apr 2, 2015

define(function (require, exports, module){
  var $ = require('$'),
    Calendar = require('calendar');

  function dateFormat(date, format){
    // 参数错误
    if (!date instanceof Date) {
      throw new TypeError('Param date must be a Date');
    }

    format = format || 'yyyy-MM-dd hh:mm:ss';

    var map = {
      'M': date.getMonth() + 1, //月份
      'd': date.getDate(), //日
      'h': date.getHours(), //小时
      'm': date.getMinutes(), //分
      's': date.getSeconds(), //秒
      'q': Math.floor((date.getMonth() + 3) / 3), //季度
      'S': date.getMilliseconds() //毫秒
    };

    format = format.replace(/([yMdhmsqS])+/g, function (all, t){
      var v = map[t];

      if (v !== undefined) {
        if (all.length > 1) {
          v = '0' + v;
          v = v.substr(v.length - 2);
        }

        return v;
      } else if (t === 'y') {
        return (date.getFullYear() + '').substr(4 - all.length);
      }

      return all;
    });

    return format;
  }

  function dateRange(start, end, startRange, endRange){
    start = $(start);
    end = $(end);
    startRange = Array.isArray(startRange) ? startRange : [startRange];
    endRange = Array.isArray(endRange) ? endRange : [null, endRange];

    var today = new Date(),
      startTime = new Date(start.val() || today),
      endTime = new Date(end.val() || today);

    if (startTime > endTime) {
      startTime = [startTime, endTime];
      endTime = startTime[0];
      startTime = startTime[1];
    }

    startTime = startTime > today ? today : startTime;
    endTime = endTime > today ? today : endTime;
    startTime = dateFormat(startTime, 'yyyy-MM-dd');
    endTime = dateFormat(endTime, 'yyyy-MM-dd');
    today = dateFormat(today, 'yyyy-MM-dd');

    // 格式化日期范围
    startRange[0] = startRange[0] ? startRange[0] : null;
    startRange[1] = endTime;
    endRange[0] = startTime;
    endRange[1] = endRange[1] || endRange[1] === null ? endRange[1] : today;

    start = new Calendar({
      trigger: start,
      range: startRange
    });

    end = new Calendar({
      trigger: end,
      range: endRange
    });

    // 查询开始日期
    start.on('selectDate', function (date){
      end.range([date, endRange[1]]);
    });

    // 查询结束日期
    end.on('selectDate', function (date){
      start.range([startRange[0], date]);
    });

    return {
      start: start,
      end: end
    }
  }

  module.exports = dateRange;
});
// 调用
dateRange(joinTime, officialTime, null, null);

1、当前日期是2015-04-02
2、初始日期都是空
qq 20150402171352
3、第一个日历选择2014-06-01(月份大于当前日期的月份),选择后第二个日历渲染错误
qq 20150402171407
4、打开第二个日历的年份渲染错误
qq 20150402171422

这个#68应该是相同问题照成的!

@nuintun
Copy link
Author

nuintun commented Apr 10, 2015

新版已修复,close

@nuintun nuintun closed this as completed Apr 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant