Skip to content

Commit

Permalink
fix(module: datepicker): add minuteStep support (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuonuoge authored and Guoyuanqiang committed Jun 24, 2019
1 parent b0ca5ba commit 246c222
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
19 changes: 19 additions & 0 deletions components/date-picker/date-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ describe('DatePickerComponent', () => {
datePickerEle.querySelector('.am-picker-popup-header-right').click();
});

it('should minuteStep work', () => {
component.mode = 'datetime';
component.minuteStep = 5;
fixture.detectChanges();
button.click();
fixture.detectChanges();
datePickerEle = document.querySelector('datepicker');
const contentEles = datePickerEle.querySelectorAll('.am-picker-col-content');
const minuteEles = contentEles[contentEles.length - 1].querySelectorAll('.am-picker-col-item');
const step = minuteEles[1].innerText - minuteEles[0].innerText;
expect(step).toBe(
5,
'minuteStep is 5'
);
datePickerEle.querySelector('.am-picker-popup-header-right').click();
});

it('should mode work', () => {
button.click();
fixture.detectChanges();
Expand Down Expand Up @@ -230,6 +247,7 @@ describe('DatePickerComponent', () => {
[title]="title"
[value]="value1"
[locale]="locale"
[minuteStep]="minuteStep"
class="nzm-button"
[minDate]="minDate"
[maxDate]="maxDate"
Expand Down Expand Up @@ -329,6 +347,7 @@ export class TestDatePickerBasicComponent {
value3 = new Date();
value4 = this.utcNow;

minuteStep = 1;
locale = en_US;
title = 'result';
mask = true;
Expand Down
6 changes: 4 additions & 2 deletions components/date-picker/date-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ export class DatePickerComponent implements OnInit, OnDestroy, AfterViewInit {

initData(tempArr, min, max, str, idx) {
const dataWithStr = [];
for (min; min < max + 1; min++) {
const increaseValue = str === this.localeNew.minute ? this.options.minuteStep : 1;
for (min; min < max + 1; min += increaseValue) {
tempArr.push(min);
dataWithStr.push(min + str);
}
Expand Down Expand Up @@ -678,8 +679,9 @@ export class DatePickerComponent implements OnInit, OnDestroy, AfterViewInit {
const realIdx = this.indexArray[checkIdx];
const arr = [];
let targetLong = 0;
const increaseValue = str === this.localeNew.minute ? this.options.minuteStep : 1;

for (let index = min; index < max + 1; index++) {
for (let index = min; index < max + 1; index += increaseValue) {
arr.push(index);
}

Expand Down
3 changes: 3 additions & 0 deletions components/date-picker/date-picker.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export class DatePickerDirective implements OnDestroy, OnChanges, OnInit, Contro
@Input()
use12Hours: boolean;
@Input()
minuteStep: number = 1;
@Input()
value: Date = new Date();
@Input()
mask: boolean;
Expand Down Expand Up @@ -111,6 +113,7 @@ export class DatePickerDirective implements OnDestroy, OnChanges, OnInit, Contro
'mode',
'minDate',
'maxDate',
'minuteStep',
'value',
'mask',
'title',
Expand Down

0 comments on commit 246c222

Please sign in to comment.