Skip to content

Commit

Permalink
feat: upgrade date-fns to v2
Browse files Browse the repository at this point in the history
BREAKING CHANGE: date-fns v2 or higher is now required as a peer dependency

If implementing a custom adapter, the `max` function signature has changed to accept an array of dates, instead of an infinite argument list.

The date adapters no longer accept strings as input arguments.

Closes #1064
  • Loading branch information
mattlewis92 committed Oct 19, 2019
1 parent 05c9a9a commit d4d3873
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 74 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"cp-cli": "^2.0.0",
"cross-env": "^5.2.0",
"css-loader": "^3.2.0",
"date-fns": "1.29.0",
"date-fns": "^2.0.0",
"del-cli": "^2.0.0",
"flatpickr": "^4.6.2",
"font-awesome": "^4.7.0",
Expand Down Expand Up @@ -150,7 +150,7 @@
"dependencies": {
"angular-draggable-droppable": "^4.3.2",
"angular-resizable-element": "^3.2.4",
"calendar-utils": "^0.3.3",
"calendar-utils": "^0.5.0",
"positioning": "^2.0.0"
},
"sideEffects": [
Expand Down
82 changes: 41 additions & 41 deletions projects/angular-calendar/src/date-adapters/date-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
import { DateAdapter as BaseDateAdapter } from 'calendar-utils/date-adapters/date-adapter';

export abstract class DateAdapter implements BaseDateAdapter {
abstract addWeeks(date: Date | string | number, amount: number): Date;
abstract addWeeks(date: Date | number, amount: number): Date;

abstract addMonths(date: Date | string | number, amount: number): Date;
abstract addMonths(date: Date | number, amount: number): Date;

abstract subDays(date: Date | string | number, amount: number): Date;
abstract subDays(date: Date | number, amount: number): Date;

abstract subWeeks(date: Date | string | number, amount: number): Date;
abstract subWeeks(date: Date | number, amount: number): Date;

abstract subMonths(date: Date | string | number, amount: number): Date;
abstract subMonths(date: Date | number, amount: number): Date;

abstract getISOWeek(date: Date | string | number): number;
abstract getISOWeek(date: Date | number): number;

abstract setDate(date: Date | string | number, dayOfMonth: number): Date;
abstract setDate(date: Date | number, dayOfMonth: number): Date;

abstract setMonth(date: Date | string | number, month: number): Date;
abstract setMonth(date: Date | number, month: number): Date;

abstract setYear(date: Date | string | number, year: number): Date;
abstract setYear(date: Date | number, year: number): Date;

abstract getDate(date: Date | string | number): number;
abstract getDate(date: Date | number): number;

abstract getMonth(date: Date | string | number): number;
abstract getMonth(date: Date | number): number;

abstract getYear(date: Date | string | number): number;
abstract getYear(date: Date | number): number;

abstract addDays(date: Date | string | number, amount: number): Date;
abstract addDays(date: Date | number, amount: number): Date;

abstract addHours(date: Date | string | number, amount: number): Date;
abstract addHours(date: Date | number, amount: number): Date;

abstract addMinutes(date: Date | string | number, amount: number): Date;
abstract addMinutes(date: Date | number, amount: number): Date;

abstract addSeconds(date: Date | string | number, amount: number): Date;
abstract addSeconds(date: Date | number, amount: number): Date;

abstract differenceInDays(
dateLeft: Date | string | number,
dateRight: Date | string | number
dateLeft: Date | number,
dateRight: Date | number
): number;

abstract differenceInMinutes(
dateLeft: Date | string | number,
dateRight: Date | string | number
dateLeft: Date | number,
dateRight: Date | number
): number;

abstract differenceInSeconds(
dateLeft: Date | string | number,
dateRight: Date | string | number
dateLeft: Date | number,
dateRight: Date | number
): number;

abstract endOfDay(date: Date | string | number): Date;
abstract endOfDay(date: Date | number): Date;

abstract endOfMonth(date: Date | string | number): Date;
abstract endOfMonth(date: Date | number): Date;

abstract endOfWeek(
date: Date | string | number,
date: Date | number,
options?: { weekStartsOn?: number }
): Date;

abstract getDay(date: Date | string | number): number;
abstract getDay(date: Date | number): number;

abstract isSameDay(
dateLeft: Date | string | number,
dateRight: Date | string | number
dateLeft: Date | number,
dateRight: Date | number
): boolean;

abstract isSameMonth(
dateLeft: Date | string | number,
dateRight: Date | string | number
dateLeft: Date | number,
dateRight: Date | number
): boolean;

abstract isSameSecond(
dateLeft: Date | string | number,
dateRight: Date | string | number
dateLeft: Date | number,
dateRight: Date | number
): boolean;

abstract max(...dates: Array<Date | string | number>): Date;
abstract max(dates: Array<Date | number>): Date;

abstract setHours(date: Date | string | number, hours: number): Date;
abstract setHours(date: Date | number, hours: number): Date;

abstract setMinutes(date: Date | string | number, minutes: number): Date;
abstract setMinutes(date: Date | number, minutes: number): Date;

abstract startOfDay(date: Date | string | number): Date;
abstract startOfDay(date: Date | number): Date;

abstract startOfMinute(date: Date | string | number): Date;
abstract startOfMinute(date: Date | number): Date;

abstract startOfMonth(date: Date | string | number): Date;
abstract startOfMonth(date: Date | number): Date;

abstract startOfWeek(
date: Date | string | number,
date: Date | number,
options?: { weekStartsOn?: number }
): Date;

abstract getHours(date: Date | string | number): number;
abstract getHours(date: Date | number): number;

abstract getMinutes(date: Date | string | number): number;
abstract getMinutes(date: Date | number): number;
}
24 changes: 13 additions & 11 deletions projects/angular-calendar/src/date-adapters/date-fns/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { adapterFactory as baseAdapterFactory } from 'calendar-utils/date-adapters/date-fns';
import * as addWeeks from 'date-fns/add_weeks/index';
import * as addMonths from 'date-fns/add_months/index';
import * as subDays from 'date-fns/sub_days/index';
import * as subWeeks from 'date-fns/sub_weeks/index';
import * as subMonths from 'date-fns/sub_months/index';
import * as getISOWeek from 'date-fns/get_iso_week/index';
import * as setDate from 'date-fns/set_date/index';
import * as setMonth from 'date-fns/set_month/index';
import * as setYear from 'date-fns/set_year/index';
import * as getDate from 'date-fns/get_date/index';
import * as getYear from 'date-fns/get_year/index';
import {
addWeeks,
addMonths,
subDays,
subWeeks,
subMonths,
getISOWeek,
setDate,
setMonth,
setYear,
getDate,
getYear
} from 'date-fns';
import { DateAdapter } from '../date-adapter';

export function adapterFactory(): DateAdapter {
Expand Down
22 changes: 11 additions & 11 deletions projects/angular-calendar/src/date-adapters/moment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,63 @@ export function adapterFactory(moment): DateAdapter {
return {
...baseAdapterFactory(moment),

addWeeks(date: Date | string | number, amount: number): Date {
addWeeks(date: Date | number, amount: number): Date {
return moment(date)
.add(amount, 'weeks')
.toDate();
},

addMonths(date: Date | string | number, amount: number): Date {
addMonths(date: Date | number, amount: number): Date {
return moment(date)
.add(amount, 'months')
.toDate();
},

subDays(date: Date | string | number, amount: number): Date {
subDays(date: Date | number, amount: number): Date {
return moment(date)
.subtract(amount, 'days')
.toDate();
},

subWeeks(date: Date | string | number, amount: number): Date {
subWeeks(date: Date | number, amount: number): Date {
return moment(date)
.subtract(amount, 'weeks')
.toDate();
},

subMonths(date: Date | string | number, amount: number): Date {
subMonths(date: Date | number, amount: number): Date {
return moment(date)
.subtract(amount, 'months')
.toDate();
},

getISOWeek(date: Date | string | number): number {
getISOWeek(date: Date | number): number {
return moment(date).isoWeek();
},

setDate(date: Date | string | number, dayOfMonth: number): Date {
setDate(date: Date | number, dayOfMonth: number): Date {
return moment(date)
.date(dayOfMonth)
.toDate();
},

setMonth(date: Date | string | number, month: number): Date {
setMonth(date: Date | number, month: number): Date {
return moment(date)
.month(month)
.toDate();
},

setYear(date: Date | string | number, year: number): Date {
setYear(date: Date | number, year: number): Date {
return moment(date)
.year(year)
.toDate();
},

getDate(date: Date | string | number): number {
getDate(date: Date | number): number {
return moment(date).date();
},

getYear(date: Date | string | number): number {
getYear(date: Date | number): number {
return moment(date).year();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ describe('CalendarDayViewComponent component', () => {
CalendarDayViewComponent
> = TestBed.createComponent(CalendarDayViewComponent);
fixture.componentInstance.events = [
{ start: '2017-01-01', title: '', color: { primary: '', secondary: '' } }
{ start: 1234, title: '', color: { primary: '', secondary: '' } }
] as any;
fixture.componentInstance.ngOnChanges({ events: {} });
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ describe('calendarMonthView component', () => {
> = TestBed.createComponent(CalendarMonthViewComponent);
fixture.componentInstance.viewDate = new Date('2017-01-01');
fixture.componentInstance.events = [
{ start: '2017-01-01', title: '', color: { primary: '', secondary: '' } }
{ start: 1234, title: '', color: { primary: '', secondary: '' } }
] as any;
fixture.componentInstance.ngOnChanges({ events: {}, viewDate: {} });
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ describe('calendarWeekView component', () => {
CalendarWeekViewComponent
> = TestBed.createComponent(CalendarWeekViewComponent);
fixture.componentInstance.events = [
{ start: '2017-01-01', title: '', color: { primary: '', secondary: '' } }
{ start: 1234, title: '', color: { primary: '', secondary: '' } }
] as any;
fixture.componentInstance.viewDate = new Date('2017-01-01');
fixture.componentInstance.ngOnChanges({ events: {}, viewDate: {} });
Expand Down

0 comments on commit d4d3873

Please sign in to comment.