Skip to content

Commit

Permalink
fix(module: calendar): fix calendar timepicker display title error bug (
Browse files Browse the repository at this point in the history
  • Loading branch information
3fuyu committed May 16, 2019
1 parent 3a976c5 commit 7ad01ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions components/calendar/calendar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import zhCN from './locale/zh_CN';
import enUS from './locale/en_US';
import PropsType from './calendar.props.component';
import { LocaleProviderService } from '../locale-provider/locale-provider.service';
import { mergeDateTime } from './util/index';
import { mergeDateTime, isSameDate } from './util/index';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';

Expand Down Expand Up @@ -278,10 +278,10 @@ export class CalendarComponent implements ControlValueAccessor, OnInit, OnDestro
} else {
newState = {
...newState,
timePickerTitle: +newDate >= +startDate ? locale.selectEndTime : locale.selectStartTime,
timePickerTitle: +newDate >= +startDate || isSameDate(startDate, newDate) ? locale.selectEndTime : locale.selectStartTime,
disConfirmBtn: false,
endDate:
pickTime && !useDateTime && +newDate >= +startDate
pickTime && !useDateTime && (+newDate >= +startDate || isSameDate(startDate, newDate))
? new Date(+mergeDateTime(newDate, startDate) + 3600000)
: newDate
};
Expand Down
12 changes: 12 additions & 0 deletions components/calendar/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ export const formatDate = (date: Date, format: string, locale?: Models.Locale) =
}
return format;
};

export const isSameDate = (day_one: Date, day_two: Date) => {
if (!day_one || !day_two) {
console.error('isSameDate function need two params');
return 'need two params';
}
const compareDate = day_one.getDate() === day_two.getDate();
const compareMonth = day_one.getMonth() === day_two.getMonth();
const compareYear = day_one.getFullYear() === day_two.getFullYear();

return compareDate && compareMonth && compareYear;
};

0 comments on commit 7ad01ba

Please sign in to comment.