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

feat(module:time-picker): support 12-hour with nzUse12Hours #3127

Merged
merged 21 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f86810d
docs(module: TimePicker): nz-time-picker support 12-hour (#1513)
kekehaoz Feb 27, 2019
479bad3
feat(module: TimePicker): support 12-hour(#1513)
kekehaoz Mar 13, 2019
e7de5bf
test(module: TimePicker): add unit test (#1513)
kekehaoz Mar 20, 2019
5abaeaa
Merge branch 'master' into feat/timePicker-support-12-hour
kekehaoz Mar 20, 2019
ec7a3be
build: fix build error(#1513)
kekehaoz Mar 20, 2019
94dfcc5
fix: fix lint
kekehaoz Mar 21, 2019
171bcbd
Merge branch 'zorro-master' into feat/timePicker-support-12-hour
kekehaoz Mar 21, 2019
591883f
fix: fix build error
kekehaoz Mar 21, 2019
4789c06
test(module: TimePicker): add test case
kekehaoz Mar 21, 2019
20f8cf1
test(module: TimePicker): add unit test case
kekehaoz Mar 21, 2019
4b03be5
Merge branch 'master' into feat/timePicker-support-12-hour
kekehaoz Mar 27, 2019
c2cd928
test(module:time-picker): add unit test case
kekehaoz Mar 27, 2019
838b9b9
Merge branch 'feat/timePicker-support-12-hour' of github.com:kekehaoz…
kekehaoz Mar 27, 2019
1cc23fa
Merge branch 'zorro-master' into feat/timePicker-support-12-hour
kekehaoz Mar 27, 2019
c971b7a
refactor(module:time-picker): refactor `12-hour` feature
kekehaoz Mar 28, 2019
1542fed
Merge branch 'master' into feat/timePicker-support-12-hour
kekehaoz Mar 28, 2019
1a68ae9
test(module:time-picker): add unit test for 12-hour
kekehaoz Apr 1, 2019
111435d
Merge branch 'feat/timePicker-support-12-hour' of github.com:kekehaoz…
kekehaoz Apr 1, 2019
3e2e44a
refactor(module:time-picker): use ngOnchanges
kekehaoz Apr 10, 2019
913d314
fix(module:time-picker): fix default12Hours
kekehaoz Apr 11, 2019
4fc833e
fix(module:time-picker): fix default format
kekehaoz Apr 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/time-picker/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ By clicking the input box, you can select a time from a popup panel.
| `[nzOpen]` | whether to popup panel, double binding | `boolean` | `false` |
| `[nzPlaceHolder]` | display when there's no value | `string` | `"Select a time"` |
| `[nzPopupClassName]` | className of panel | `string` | `''` |
| `[nzUse12Hours]` | display as 12 hours format, with default format h:mm:ss a | `boolean` | `false` |
| `(ngModelChange)` | a callback function, can be executed when the selected time is changing | `EventEmitter<Date>` | - |
| `(nzOpenChange)` | a callback function which will be called while panel opening/closing | `EventEmitter<boolean>` | - |

Expand Down
1 change: 1 addition & 0 deletions components/time-picker/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ title: TimePicker
| `[nzOpen]` | 面板是否打开,可双向绑定 | `boolean` | `false` |
| `[nzPlaceHolder]` | 没有值的时候显示的内容 | `string` | `"请选择时间"` |
| `[nzPopupClassName]` | 弹出层类名 | `string` | `''` |
| `[nzUse12Hours]` | 使用 12 小时制,为 true 时 format 默认为 h:mm:ss a | `boolean` | `false` |
| `(ngModelChange)` | 时间发生变化的回调 | `EventEmitter<Date>` | - |
| `(nzOpenChange)` | 面板打开/关闭时的回调 | `EventEmitter<boolean>` | - |

Expand Down
18 changes: 18 additions & 0 deletions components/time-picker/nz-time-picker-panel.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@
</ng-container>
</ul>
</div>
<div
*ngIf="nzUse12Hours"
#use12HoursListElement
class="{{ prefixCls }}-select">
<ul>
<ng-container *ngFor="let range of use12HoursRange ">
<li
*ngIf="!nzHideDisabledOptions"
(click)="select12Hours(range)"
class="
{{ isSelected12Hours(range) ? prefixCls + '-select-option-selected' : '' }}
"
>
{{ range.value }}
</li>
</ng-container>
</ul>
</div>
</div>
<div class="{{ prefixCls }}-addon" *ngIf="nzAddOn">
<ng-template [ngTemplateOutlet]="nzAddOn"></ng-template>
Expand Down
182 changes: 180 additions & 2 deletions components/time-picker/nz-time-picker-panel.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import { FormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { NzI18nModule } from '../i18n/nz-i18n.module';
import { NzTimePickerPanelComponent } from './nz-time-picker-panel.component';

describe('time-picker-panel', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [FormsModule, NzI18nModule],
schemas: [NO_ERRORS_SCHEMA],
declarations: [NzTimePickerPanelComponent, NzTestTimePanelComponent, NzTestTimePanelDisabledComponent]
declarations: [
NzTimePickerPanelComponent,
NzTestTimePanelComponent,
NzTestTimePanelDisabledComponent,
NzTest12HourTimePanelComponent,
NzTest12HourTimePanelDisabeledComponent
]
});
TestBed.compileComponents();
}));
Expand Down Expand Up @@ -149,6 +154,121 @@ describe('time-picker-panel', () => {
expect(listOfSelectContainer[2].firstElementChild.children.length).toBe(54);
}));
});
describe('12-hour time-picker-panel', () => {
let panelElement: DebugElement;
let fixture12Hour: ComponentFixture<NzTest12HourTimePanelComponent>;
let testComponent: NzTest12HourTimePanelComponent;
beforeEach(() => {
fixture12Hour = TestBed.createComponent(NzTest12HourTimePanelComponent);
testComponent = fixture12Hour.debugElement.componentInstance;
fixture12Hour.detectChanges();
panelElement = fixture12Hour.debugElement.query(By.directive(NzTimePickerPanelComponent));
});
it('basic 12-hour time-picker-panel', fakeAsync(() => {
fixture12Hour.detectChanges();
expect(testComponent.nzTimePickerPanelComponent.enabledColumns).toBe(4);
const listColumns: HTMLElement[] = panelElement.nativeElement.querySelectorAll('.ant-time-picker-panel-select');
expect(listColumns[0].querySelectorAll('li')[0].innerText).toBe('12');
const hour12labels = listColumns[3].querySelectorAll('li');
expect(hour12labels[0].innerText).toBe('am');
expect(hour12labels[1].innerText).toBe('pm');
}));
it('default value 12-hour time-picker-panel', fakeAsync(() => {
testComponent.nzTimePickerPanelComponent.opened = true;
fixture12Hour.detectChanges();
tick(1000);
fixture12Hour.detectChanges();
let listOfSelectedLi = panelElement.nativeElement.querySelectorAll(
'.ant-time-picker-panel-select-option-selected'
);
expect(listOfSelectedLi[0].innerText).toBe('12');
expect(listOfSelectedLi[1].innerText).toBe('00');
expect(listOfSelectedLi[2].innerText).toBe('00');
expect(listOfSelectedLi[3].innerText).toBe('am');
fixture12Hour.componentInstance.nzTimePickerPanelComponent.select12Hours({ index: 1, value: 'pm' });
fixture12Hour.componentInstance.openValue = new Date(0, 0, 0, 5, 6, 7);
fixture12Hour.detectChanges();
fixture12Hour.componentInstance.nzTimePickerPanelComponent.opened = false;
fixture12Hour.detectChanges();
tick(1000);
fixture12Hour.detectChanges();
fixture12Hour.componentInstance.nzTimePickerPanelComponent.opened = true;
fixture12Hour.detectChanges();
tick(1000);
fixture12Hour.detectChanges();
listOfSelectedLi = panelElement.nativeElement.querySelectorAll('.ant-time-picker-panel-select-option-selected');
expect(listOfSelectedLi[0].innerText).toBe('05');
expect(listOfSelectedLi[1].innerText).toBe('06');
expect(listOfSelectedLi[2].innerText).toBe('07');
expect(listOfSelectedLi[3].innerText).toBe('pm');
}));
it('select hour and 12-hour in 12-hour-time-picker-panel', fakeAsync(() => {
fixture12Hour.detectChanges();
testComponent.nzTimePickerPanelComponent.selectHour({ index: 3, disabled: false });
testComponent.nzTimePickerPanelComponent.select12Hours({ index: 1, value: 'pm' });
fixture12Hour.detectChanges();
flush();
fixture12Hour.detectChanges();
expect(testComponent.value.getHours()).toBe(15);
testComponent.nzTimePickerPanelComponent.select12Hours({ index: 0, value: 'am' });
fixture12Hour.detectChanges();
flush();
fixture12Hour.detectChanges();
expect(testComponent.value.getHours()).toBe(3);
}));
it('hour step in 12-hour-time-picker-panel', fakeAsync(() => {
testComponent.hourStep = 2;
fixture12Hour.detectChanges();
const listOfHourContainer = panelElement.nativeElement.querySelectorAll('.ant-time-picker-panel-select');
expect(listOfHourContainer[0].firstElementChild.children.length).toEqual(6);
}));
});

describe('disabled and format 12-hour time-picker-panel', () => {
let panelElement: DebugElement;
let fixture12Hour: ComponentFixture<NzTest12HourTimePanelDisabeledComponent>;
let testComponent: NzTest12HourTimePanelDisabeledComponent;

beforeEach(() => {
fixture12Hour = TestBed.createComponent(NzTest12HourTimePanelDisabeledComponent);
testComponent = fixture12Hour.debugElement.componentInstance;
fixture12Hour.detectChanges();
panelElement = fixture12Hour.debugElement.query(By.directive(NzTimePickerPanelComponent));
});

it('format in 12-hour-time-pick-panle', fakeAsync(() => {
testComponent.format = 'hh:mm:ss A';
fixture12Hour.detectChanges();
const list12HourLi = panelElement.nativeElement
.querySelectorAll('.ant-time-picker-panel-select')[3]
.querySelectorAll('li');
expect(list12HourLi[0].innerText).toBe('AM');
expect(list12HourLi[1].innerText).toBe('PM');
}));

it('disabled hour in 12-hour-time-picker-panel', fakeAsync(() => {
fixture12Hour.detectChanges();
flush();
testComponent.disabledHours = (): number[] => [0, 3, 4, 5, 12, 18, 19, 20, 24];
fixture12Hour.detectChanges();
let listHourLi = panelElement.nativeElement
.querySelectorAll('.ant-time-picker-panel-select')[0]
.querySelectorAll('li');
expect(listHourLi[0].classList).toContain('ant-time-picker-panel-select-option-disabled');
expect(listHourLi[3].classList).toContain('ant-time-picker-panel-select-option-disabled');
expect(listHourLi[4].classList).toContain('ant-time-picker-panel-select-option-disabled');
expect(listHourLi[5].classList).toContain('ant-time-picker-panel-select-option-disabled');
testComponent.nzTimePickerPanelComponent.select12Hours({ index: 1, value: 'pm' });
fixture12Hour.detectChanges();
listHourLi = panelElement.nativeElement
.querySelectorAll('.ant-time-picker-panel-select')[0]
.querySelectorAll('li');
expect(listHourLi[0].classList).toContain('ant-time-picker-panel-select-option-disabled');
expect(listHourLi[6].classList).toContain('ant-time-picker-panel-select-option-disabled');
expect(listHourLi[7].classList).toContain('ant-time-picker-panel-select-option-disabled');
expect(listHourLi[8].classList).toContain('ant-time-picker-panel-select-option-disabled');
}));
});
});

@Component({
Expand Down Expand Up @@ -229,3 +349,61 @@ export class NzTestTimePanelDisabledComponent {
}
}
}
@Component({
selector: 'nz-test-12-hour-time-panel',
encapsulation: ViewEncapsulation.None,
template: `
<nz-time-picker-panel
[(ngModel)]="value"
[nzUse12Hours]="true"
[nzDefaultOpenValue]="openValue"
[nzHourStep]="hourStep"
[format]="format"
>
</nz-time-picker-panel>
`,
styleUrls: ['../style/index.less', './style/index.less']
})
export class NzTest12HourTimePanelComponent {
@ViewChild(NzTimePickerPanelComponent) nzTimePickerPanelComponent: NzTimePickerPanelComponent;
format = 'hh:mm:ss a';
hourStep = 1;
value: Date;
openValue = new Date(0, 0, 0, 0, 0, 0);
}
@Component({
selector: 'nz-test-12-hour-time-panel',
encapsulation: ViewEncapsulation.None,
template: `
<nz-time-picker-panel
[format]="format"
[(ngModel)]="value"
[nzUse12Hours]="true"
[nzDisabledHours]="disabledHours"
[nzDisabledMinutes]="disabledMinutes"
[nzDisabledSeconds]="disabledSeconds"
>
</nz-time-picker-panel>
`,
styleUrls: ['../style/index.less', './style/index.less']
})
export class NzTest12HourTimePanelDisabeledComponent {
@ViewChild(NzTimePickerPanelComponent) nzTimePickerPanelComponent: NzTimePickerPanelComponent;
format = 'hh:mm:ss a';
value = new Date(0, 0, 0, 1, 1, 1);
disabledHours = (): number[] => [];
disabledMinutes(hour: number): number[] {
if (hour === 4) {
return [20, 21, 22, 23, 24, 25];
} else {
return [];
}
}
disabledSeconds(hour: number, minute: number): number[] {
if (hour === 5 && minute === 1) {
return [20, 21, 22, 23, 24, 25];
} else {
return [];
}
}
}
Loading