Skip to content

Commit

Permalink
fix(ui): calendar - replace UTC dates with regular dates
Browse files Browse the repository at this point in the history
  • Loading branch information
artyorsh authored Nov 13, 2019
1 parent d5ee185 commit 700a902
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/framework/ui/calendar/calendar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TestApplication extends React.Component<TestAppProps, State> {
describe('@calendar: component checks', () => {

it('* date changes', () => {
const expectedDate: Date = new Date(Date.UTC(2019, CURRENT_MONTH, 5));
const expectedDate: Date = new Date(2019, CURRENT_MONTH, 5);
const application: RenderAPI = render(<TestApplication/>);

fireEvent.press(application.getAllByText('5')[1]);
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('@calendar: component checks', () => {
it('* day view appear/month select', () => {
const month: number = 1 - 1;
const expectedViewModeId: string = 'DATE';
const expectedVisibleDate: Date = new Date(Date.UTC(2018, month, 1));
const expectedVisibleDate: Date = new Date(2018, month, 1);
const calendarRef: React.LegacyRef<CalendarComponent<Date>> = React.createRef();
const application: RenderAPI = render(
<TestApplication
Expand Down
10 changes: 5 additions & 5 deletions src/framework/ui/calendar/rangeCalendar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TestApplication extends React.Component<TestAppProps, State> {
describe('@calendar: component checks', () => {

it('* start range date selected properly', () => {
const expectedStartDate: Date = new Date(Date.UTC(2019, CURRENT_MONTH, 11));
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 11);
const application: RenderAPI = render(<TestApplication/>);

fireEvent.press(application.getAllByText('11')[1]);
Expand All @@ -66,8 +66,8 @@ describe('@calendar: component checks', () => {
});

it('* range selected works properly', () => {
const expectedStartDate: Date = new Date(Date.UTC(2019, CURRENT_MONTH, 11));
const expectedEndDate: Date = new Date(Date.UTC(2019, CURRENT_MONTH, 26));
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 11);
const expectedEndDate: Date = new Date(2019, CURRENT_MONTH, 26);
const application: RenderAPI = render(<TestApplication/>);

fireEvent.press(application.getAllByText('11')[1]);
Expand All @@ -79,7 +79,7 @@ describe('@calendar: component checks', () => {
});

it('* range re-selected properly 1', () => {
const expectedStartDate: Date = new Date(Date.UTC(2019, CURRENT_MONTH, 19));
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 19);
const application: RenderAPI = render(<TestApplication/>);

fireEvent.press(application.getAllByText('11')[1]);
Expand All @@ -92,7 +92,7 @@ describe('@calendar: component checks', () => {
});

it('* range re-selected properly 2', () => {
const expectedStartDate: Date = new Date(Date.UTC(2019, CURRENT_MONTH, 8));
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 8);
const application: RenderAPI = render(<TestApplication/>);

fireEvent.press(application.getAllByText('11')[1]);
Expand Down
28 changes: 14 additions & 14 deletions src/framework/ui/calendar/service/nativeDate.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ describe('@native-date: service checks', () => {
});

it('* should get year end', () => {
const date: Date = new Date(Date.UTC(2018, 5, 15));
expect(dateService.getYearEnd(date)).toEqual(new Date(Date.UTC(2018, 11, 31)));
const date: Date = new Date(2018, 5, 15);
expect(dateService.getYearEnd(date)).toEqual(new Date(2018, 11, 31));
});

it('* should get year start', () => {
const date: Date = new Date(Date.UTC(2018, 5, 15));
expect(dateService.getYearStart(date)).toEqual(new Date(Date.UTC(2018, 0, 1)));
const date: Date = new Date(2018, 5, 15);
expect(dateService.getYearStart(date)).toEqual(new Date(2018, 0, 1));
});

it('* should get number of days in month', () => {
Expand All @@ -154,43 +154,43 @@ describe('@native-date: service checks', () => {
});

it('* should add day', () => {
const newDate = dateService.addDay(new Date(Date.UTC(2018, 6, 16)), 1);
expect(newDate.getTime()).toBe(new Date(Date.UTC(2018, 6, 17)).getTime());
const newDate = dateService.addDay(new Date(2018, 6, 16), 1);
expect(newDate.getTime()).toBe(new Date(2018, 6, 17).getTime());
});

it('* should add day in the end of the year', () => {
const newDate = dateService.addDay(new Date(2018, 11, 31), 1);
expect(newDate.getTime()).toBe(new Date(Date.UTC(2019, 0, 1)).getTime());
expect(newDate.getTime()).toBe(new Date(2019, 0, 1).getTime());
});

it('* should add day in the leap year', () => {
const newDate = dateService.addDay(new Date(2016, 1, 29), 1);
expect(newDate.getTime()).toBe(new Date(Date.UTC(2016, 2, 1)).getTime());
expect(newDate.getTime()).toBe(new Date(2016, 2, 1).getTime());
});

it('* should add month', () => {
const newDate = dateService.addMonth(new Date(2018, 6, 16), 1);
expect(newDate.getTime()).toBe(new Date(Date.UTC(2018, 7, 16)).getTime());
expect(newDate.getTime()).toBe(new Date(2018, 7, 16).getTime());
});

it('* should add month in the end of the year', () => {
const newDate = dateService.addMonth(new Date(2018, 11, 16), 1);
expect(newDate.getTime()).toBe(new Date(Date.UTC(2019, 0, 16)).getTime());
expect(newDate.getTime()).toBe(new Date(2019, 0, 16).getTime());
});

it('* should add month if number of days will be less than current date', () => {
const newDate = dateService.addMonth(new Date(2018, 11, 31), -1);
expect(newDate.getTime()).toBe(new Date(Date.UTC(2018, 10, 30)).getTime());
expect(newDate.getTime()).toBe(new Date(2018, 10, 30).getTime());
});

it('* should add year', () => {
const newDate = dateService.addYear(new Date(2018, 11, 16), 1);
expect(newDate.getTime()).toBe(new Date(Date.UTC(2019, 11, 16)).getTime());
expect(newDate.getTime()).toBe(new Date(2019, 11, 16).getTime());
});

it('* should create date', () => {
const date = dateService.createDate(2018, 6, 16);
expect(date).toEqual(new Date(Date.UTC(2018, 6, 16)));
expect(date).toEqual(new Date(2018, 6, 16));
});

it('* should create date for two digit year', () => {
Expand All @@ -207,7 +207,7 @@ describe('@native-date: service checks', () => {

it('* should get month start', () => {
const date = dateService.getMonthStart(new Date(2018, 6, 16));
expect(date.getTime()).toBe(new Date(Date.UTC(2018, 6, 1)).getTime());
expect(date.getTime()).toBe(new Date(2018, 6, 1).getTime());
});

it('* should compare years correctly', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/framework/ui/calendar/service/nativeDate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class NativeDateService extends DateService<Date> {
}

public createDate(year: number, month: number, date: number): Date {
const result = new Date(Date.UTC(year, month, date));
const result = new Date(year, month, date);

// We need to correct for the fact that JS native Date treats years in range [0, 99] as
// abbreviations for 19xx.
Expand Down
32 changes: 16 additions & 16 deletions src/framework/ui/calendar/service/rangeDate.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('@range service checks', () => {

it('* getRange (only start date)', () => {
const expectedRange: CalendarRange<Date> = {
startDate: new Date(Date.UTC(2019, 8, 12)),
startDate: new Date(2019, 8, 12),
endDate: null,
};
const date: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 12)),
date: new Date(2019, 8, 12),
bounding: false,
holiday: false,
};
Expand All @@ -35,16 +35,16 @@ describe('@range service checks', () => {

it('* getRange (full range)', () => {
const expectedRange: CalendarRange<Date> = {
startDate: new Date(Date.UTC(2019, 8, 12)),
endDate: new Date(Date.UTC(2019, 8, 24)),
startDate: new Date(2019, 8, 12),
endDate: new Date(2019, 8, 24),
};
const date1: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 12)),
date: new Date(2019, 8, 12),
bounding: false,
holiday: false,
};
const date2: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 24)),
date: new Date(2019, 8, 24),
bounding: false,
holiday: false,
};
Expand All @@ -56,21 +56,21 @@ describe('@range service checks', () => {

it('* getRange (re-select with only start date)', () => {
const expectedRange: CalendarRange<Date> = {
startDate: new Date(Date.UTC(2019, 8, 19)),
startDate: new Date(2019, 8, 19),
endDate: null,
};
const date1: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 12)),
date: new Date(2019, 8, 12),
bounding: false,
holiday: false,
};
const date2: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 24)),
date: new Date(2019, 8, 24),
bounding: false,
holiday: false,
};
const date3: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 19)),
date: new Date(2019, 8, 19),
bounding: false,
holiday: false,
};
Expand All @@ -83,26 +83,26 @@ describe('@range service checks', () => {

it('* getRange (re-select with full range)', () => {
const expectedRange: CalendarRange<Date> = {
startDate: new Date(Date.UTC(2019, 8, 10)),
endDate: new Date(Date.UTC(2019, 8, 13)),
startDate: new Date(2019, 8, 10),
endDate: new Date(2019, 8, 13),
};
const date1: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 12)),
date: new Date(2019, 8, 12),
bounding: false,
holiday: false,
};
const date2: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 24)),
date: new Date(2019, 8, 24),
bounding: false,
holiday: false,
};
const date3: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 10)),
date: new Date(2019, 8, 10),
bounding: false,
holiday: false,
};
const date4: CalendarDateInfo<Date> = {
date: new Date(Date.UTC(2019, 8, 13)),
date: new Date(2019, 8, 13),
bounding: false,
holiday: false,
};
Expand Down

0 comments on commit 700a902

Please sign in to comment.