Skip to content

Commit

Permalink
fix(module: datepicker): fix new Date init in safari would be invlid …
Browse files Browse the repository at this point in the history
…date. (#454)
  • Loading branch information
Guoyuanqiang authored and fisherspy committed May 23, 2019
1 parent f3e77c0 commit 87c62a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/date-picker/date-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,12 @@ export class DatePickerComponent implements OnInit, OnDestroy, AfterViewInit {
const temp = this.resultArr;
result = temp.slice(0, 3).join('-') + ' ' + temp.slice(3, 5).join(':');
} else {
result = this.resultArr.map(v => v).join('-');
if (this.resultArr.length < 3) {
this.resultArr.push('1');
}
result = this.resultArr.map(v => {
return this.preZero(parseInt(v, 0));
}).join('-');
}
this.resultDate = new Date(result.replace(/-/g, '/'));
if (this.options.minDate.getTime() > this.resultDate.getTime()) {
Expand Down
18 changes: 18 additions & 0 deletions components/date-picker/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ import { en_US, ru_RU, zh_CN, sv_SE, da_DK } from 'ng-zorro-antd-mobile';
Datetime
<Brief>{{ name1 }}</Brief>
</ListItem>
<ListItem
DatePicker
[extra]="currentDateFormat(value7,'yyyy-mm')"
[arrow]="'horizontal'"
[mode]="'month'"
[(ngModel)]="value7"
(onOk)="onOk7($event)"
>
Month
<Brief>{{ name7 }}</Brief>
</ListItem>
<ListItem
DatePicker
[extra]="currentDateFormat(value2, 'yyyy-mm-dd')"
Expand Down Expand Up @@ -102,6 +113,7 @@ export class DemoDatePickerBasicComponent {
name4 = '选择';
name5 = '当前时间小于最小时间';
name6 = '当前时间大于最大时间';
name7 = '选择';

nowTimeStamp = Date.now();
now = new Date(this.nowTimeStamp);
Expand All @@ -114,6 +126,7 @@ export class DemoDatePickerBasicComponent {
value4 = this.utcNow;
value5 = new Date(1999, 1, 1, 1, 1);
value6 = new Date(2031, 1, 1, 1, 1);
value7 = new Date(2019, 1);

currentDateFormat(date, format: string = 'yyyy-mm-dd HH:MM'): any {
const pad = (n: number): string => (n < 10 ? `0${n}` : n.toString());
Expand Down Expand Up @@ -156,6 +169,11 @@ export class DemoDatePickerBasicComponent {
this.value6 = result;
}

onOk7(result: Date) {
this.name7 = this.currentDateFormat(result, 'yyyy-mm');
this.value7 = result;
}

formatIt(date: Date, form: string) {
const pad = (n: number) => (n < 10 ? `0${n}` : n);
const dateStr = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
Expand Down

1 comment on commit 87c62a3

@xinFengQi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

时间选择器控件选择第一年时候,在ios上会出现无效时间Nan

Please sign in to comment.