Skip to content

Commit

Permalink
fix(datepicker): fix datepicker format not available error (#1117)
Browse files Browse the repository at this point in the history
Closes #1088
  • Loading branch information
tibing-old-email authored and nnixaa committed Dec 30, 2018
1 parent fef2a9a commit 83cda23
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/framework/date-fns/services/date-fns-date.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ export class NbDateFnsDateService extends NbNativeDateService {
parse(date: string, format: string): Date {
return parse(date, format, new Date());
}

getId(): string {
return 'date-fns';
}
}
4 changes: 4 additions & 0 deletions src/framework/moment/services/moment-date.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export class NbMomentDateService extends NbDateService<Moment> {
return moment();
}

getId(): string {
return 'moment';
}

protected setMomentLocaleData(locale: string) {
const momentLocaleData = moment.localeData(locale);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,6 @@ export abstract class NbDateService<D> {
* Returns date with added number of years.
* */
abstract addYear(date: D, years: number): D;

abstract getId(): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ export class NbNativeDateService extends NbDateService<Date> {
isSameYear(date1: Date, date2: Date): boolean {
return date1.getFullYear() === date2.getFullYear();
}

getId(): string {
return 'native';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
NbCalendarSize,
NbCalendarViewMode,
NbDateService,
NbNativeDateService,
} from '../calendar-kit';
import { NbDatepicker, NbPickerValidatorConfig } from './datepicker.directive';

Expand Down Expand Up @@ -198,7 +197,7 @@ export abstract class NbBasePicker<D, T, P> extends NbDatepicker<T> implements O
protected abstract get pickerValueChange(): Observable<T>;

ngOnChanges() {
if (this.dateService instanceof NbNativeDateService && this.format) {
if (this.dateService.getId() === 'native' && this.format) {
throw new Error('Can\'t format native date. To use custom formatting you have to install @nebular/moment or ' +
'@nebular/date-fns package and import NbMomentDateModule or NbDateFnsDateModule accordingly.' +
'More information at "Formatting issue" ' +
Expand Down

0 comments on commit 83cda23

Please sign in to comment.