Skip to content

Commit

Permalink
refactor(datepicker): replace SimpleDate & CalendarLocale with DateAd…
Browse files Browse the repository at this point in the history
…apter (#4189)

* rename test file to match the file its testing

* remove SimpleDate and CalendarLocale

* switch MdMonthView to use DateAdapter

* swtich MdYearView to use DateAdapter

* switch MdCalendar to use DateAdapter

* switch MdDatepicker to use DateAdapter

* switch MdDatepickerInput and MdDatepickerToggle to use DateAdapter

* fix demo

* fix some small bugs

* fix tests

* alias months in tests

* address comments and remove overflow on createDate

* s/l10n/intl
  • Loading branch information
mmalerba committed Apr 29, 2017
1 parent 3b19607 commit d2016b5
Show file tree
Hide file tree
Showing 25 changed files with 491 additions and 873 deletions.
6 changes: 3 additions & 3 deletions src/demo-app/datepicker/datepicker-demo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Component} from '@angular/core';
import {SimpleDate} from '@angular/material';


@Component({
Expand All @@ -9,8 +8,9 @@ import {SimpleDate} from '@angular/material';
styleUrls: ['datepicker-demo.css'],
})
export class DatepickerDemo {
date: SimpleDate;
date: Date;
touch = false;
dateFilter = (date: SimpleDate) => !this._blacklistedMonths.has(date.month) && date.date % 2 == 0;
dateFilter =
(date: Date) => !this._blacklistedMonths.has(date.getMonth()) && date.getDate() % 2 == 0
private _blacklistedMonths = new Set([2, 3]);
}
105 changes: 0 additions & 105 deletions src/lib/core/datetime/calendar-locale.spec.ts

This file was deleted.

201 changes: 0 additions & 201 deletions src/lib/core/datetime/calendar-locale.ts

This file was deleted.

18 changes: 12 additions & 6 deletions src/lib/core/datetime/date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export abstract class DateAdapter<D> {
*/
abstract getFirstDayOfWeek(): number;

/**
* Gets the number of days in the month of the given date.
* @param date The date whose month should be checked.
* @returns The number of days in the month of the given date.
*/
abstract getNumDaysInMonth(date: D): number;

/**
* Gets a set of default formats to use for displaying the date in different contexts.
* @returns An object with the following default formats:
Expand All @@ -88,13 +95,12 @@ export abstract class DateAdapter<D> {
abstract clone(date: D): D;

/**
* Creates a date with the given year, month, and date.
* Creates a date with the given year, month, and date. Does not allow over/under-flow of the
* month and date.
* @param year The full year of the date. (e.g. 89 means the year 89, not the year 1989).
* @param month The month of the date (0-indexed, 0 = January). If `month` is less than 0 or
* greater than 11, it should roll into the previous / next year.
* @param date The date of month of the date. If `date` is less than 1 or greater than the number
* of days in the `month`, it should roll into the previous / next month.
* @returns The new date.
* @param month The month of the date (0-indexed, 0 = January). Must be an integer 0 - 11.
* @param date The date of month of the date. Must be an integer 1 - length of the given month.
* @returns The new date, or null if invalid.
*/
abstract createDate(year: number, month: number, date: number): D;

Expand Down
7 changes: 3 additions & 4 deletions src/lib/core/datetime/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {NgModule} from '@angular/core';
import {DefaultCalendarLocale, CalendarLocale} from './calendar-locale';
import {DateAdapter} from './date-adapter';
import {NativeDateAdapter} from './native-date-adapter';


export * from './calendar-locale';
export * from './date-adapter';
export * from './simple-date';
export * from './native-date-adapter';


@NgModule({
providers: [{provide: CalendarLocale, useClass: DefaultCalendarLocale}],
providers: [{provide: DateAdapter, useClass: NativeDateAdapter}],
})
export class DatetimeModule {}
Loading

0 comments on commit d2016b5

Please sign in to comment.