Skip to content

Commit

Permalink
bug fix 修复在非 cron 下起始日期不准确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
0ahz committed Mar 22, 2019
1 parent ea81b1e commit 36752fc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
12 changes: 9 additions & 3 deletions dist/example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
// 时间选择器
document.querySelector('#datePickerBtn100').addEventListener('click', function () {
_weui2.default.datePicker({
start: '1816-12-29',
start: '1816-03-29',
end: '2030-12-29',
/**
* https://zh.wikipedia.org/wiki/Cron
Expand Down Expand Up @@ -4555,7 +4555,7 @@
var hasLeapYear = function hasLeapYear(year) {
return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
};
var createDaysArr = function createDaysArr(hasLeap, month, startDay, endDay) {
var createDaysArr = function createDaysArr(hasLeap, month, startMonth, endMonth, startDay, endDay) {
var daysArr = [];
var maxDays = hasLeap ? 29 : 28;
switch (month) {
Expand All @@ -4580,6 +4580,12 @@
}
startDay = startDay || 1;
endDay = endDay || maxDays;
if (month > startMonth) {
startDay = 1;
}
if (month < endMonth) {
endDay = maxDays;
}
if (startDay > maxDays) {
startDay = maxDays;
}
Expand All @@ -4598,7 +4604,7 @@
monthsArr.push({
label: i + '月',
value: i,
children: createDaysArr(hasLeap, i, startDay, endDay)
children: createDaysArr(hasLeap, i, startMonth, endMonth, startDay, endDay)
});
}
return monthsArr;
Expand Down
10 changes: 8 additions & 2 deletions dist/weui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3190,7 +3190,7 @@ return /******/ (function(modules) { // webpackBootstrap
var hasLeapYear = function hasLeapYear(year) {
return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
};
var createDaysArr = function createDaysArr(hasLeap, month, startDay, endDay) {
var createDaysArr = function createDaysArr(hasLeap, month, startMonth, endMonth, startDay, endDay) {
var daysArr = [];
var maxDays = hasLeap ? 29 : 28;
switch (month) {
Expand All @@ -3215,6 +3215,12 @@ return /******/ (function(modules) { // webpackBootstrap
}
startDay = startDay || 1;
endDay = endDay || maxDays;
if (month > startMonth) {
startDay = 1;
}
if (month < endMonth) {
endDay = maxDays;
}
if (startDay > maxDays) {
startDay = maxDays;
}
Expand All @@ -3233,7 +3239,7 @@ return /******/ (function(modules) { // webpackBootstrap
monthsArr.push({
label: i + '月',
value: i,
children: createDaysArr(hasLeap, i, startDay, endDay)
children: createDaysArr(hasLeap, i, startMonth, endMonth, startDay, endDay)
});
}
return monthsArr;
Expand Down
2 changes: 1 addition & 1 deletion dist/weui.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ document.querySelector('#datePickerBtn').addEventListener('click', function () {
// 时间选择器
document.querySelector('#datePickerBtn100').addEventListener('click', function () {
weui.datePicker({
start: '1816-12-29',
start: '1816-03-29',
end: '2030-12-29',
/**
* https://zh.wikipedia.org/wiki/Cron
Expand Down
10 changes: 8 additions & 2 deletions src/picker/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ function datePicker(options) {

const date2arr = date => [date.getFullYear(), date.getMonth() + 1, date.getDate()];
const hasLeapYear = year => year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
const createDaysArr = (hasLeap, month, startDay, endDay) => {
const createDaysArr = (hasLeap, month, startMonth, endMonth, startDay, endDay) => {
const daysArr = [];
let maxDays = hasLeap ? 29 : 28;
switch (month) {
Expand All @@ -513,6 +513,12 @@ function datePicker(options) {
}
startDay = startDay || 1;
endDay = endDay || maxDays;
if (month > startMonth) {
startDay = 1;
}
if (month < endMonth) {
endDay = maxDays;
}
if (startDay > maxDays) {
startDay = maxDays;
}
Expand All @@ -531,7 +537,7 @@ function datePicker(options) {
monthsArr.push({
label: i + '月',
value: i,
children: createDaysArr(hasLeap, i, startDay, endDay),
children: createDaysArr(hasLeap, i, startMonth, endMonth, startDay, endDay),
});
}
return monthsArr;
Expand Down

0 comments on commit 36752fc

Please sign in to comment.