refactor(date-picker): value converter for month is 1-based (#4656)

This commit is contained in:
Stanimira Vlaeva
2017-08-08 17:07:21 +03:00
committed by GitHub
parent 24923445bd
commit 08dcfabe82
6 changed files with 25 additions and 57 deletions

View File

@@ -5,7 +5,7 @@ export function getNativeYear(datePicker: datePickerModule.DatePicker): number {
}
export function getNativeMonth(datePicker: datePickerModule.DatePicker): number {
return datePicker.android.getMonth();
return datePicker.android.getMonth() + 1;
}
export function getNativeDay(datePicker: datePickerModule.DatePicker): number {
@@ -25,7 +25,7 @@ export function setNativeYear(datePicker: datePickerModule.DatePicker, value: nu
}
export function setNativeMonth(datePicker: datePickerModule.DatePicker, value: number): void {
datePicker.android.updateDate(datePicker.android.getYear(), value, datePicker.android.getDayOfMonth());
datePicker.android.updateDate(datePicker.android.getYear(), value - 1, datePicker.android.getDayOfMonth());
}
export function setNativeDay(datePicker: datePickerModule.DatePicker, value: number): void {
@@ -33,5 +33,5 @@ export function setNativeDay(datePicker: datePickerModule.DatePicker, value: num
}
export function setNativeDate(datePicker: datePickerModule.DatePicker, year: number, month: number, day: number): void {
datePicker.android.updateDate(year, month, day);
datePicker.android.updateDate(year, month - 1, day);
}

View File

@@ -7,7 +7,7 @@ export function getNativeYear(datePicker: datePickerModule.DatePicker): number {
}
export function getNativeMonth(datePicker: datePickerModule.DatePicker): number {
return utils.ios.getter(NSCalendar, NSCalendar.currentCalendar).componentsFromDate(NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitDay, datePicker.ios.date).month - 1;
return utils.ios.getter(NSCalendar, NSCalendar.currentCalendar).componentsFromDate(NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitDay, datePicker.ios.date).month;
}
export function getNativeDay(datePicker: datePickerModule.DatePicker): number {
@@ -31,7 +31,7 @@ export function setNativeYear(datePicker: datePickerModule.DatePicker, value: nu
export function setNativeMonth(datePicker: datePickerModule.DatePicker, value: number): void {
var comps = utils.ios.getter(NSCalendar, NSCalendar.currentCalendar).componentsFromDate(NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitDay, datePicker.ios.date);
comps.month = value + 1;
comps.month = value;
datePicker.ios.setDateAnimated(utils.ios.getter(NSCalendar, NSCalendar.currentCalendar).dateFromComponents(comps), false);
(<any>datePicker)._changeHandler.valueChanged(datePicker.ios);
}
@@ -46,7 +46,7 @@ export function setNativeDay(datePicker: datePickerModule.DatePicker, value: num
export function setNativeDate(datePicker: datePickerModule.DatePicker, year: number, month: number, day: number): void {
var comps = utils.ios.getter(NSCalendar, NSCalendar.currentCalendar).componentsFromDate(NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitDay, datePicker.ios.date);
comps.year = year;
comps.month = month + 1;
comps.month = month;
comps.day = day;
datePicker.ios.setDateAnimated(utils.ios.getter(NSCalendar, NSCalendar.currentCalendar).dateFromComponents(comps), false);
(<any>datePicker)._changeHandler.valueChanged(datePicker.ios);

View File

@@ -89,7 +89,7 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
public test_WhenCreated_MonthIsCurrentMonth() {
const actualValue = this.testView.month;
const expectedValue = currentDate.getMonth();
const expectedValue = currentDate.getMonth() + 1;
TKUnit.assertEqual(actualValue, expectedValue);
}
@@ -99,11 +99,6 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
TKUnit.assertEqual(actualValue, expectedValue);
}
public test_WhenCreated_DateIsCurrentDate() {
const expectedValue = currentDate;
assertDate(this.testView, expectedValue.getFullYear(), expectedValue.getMonth(), expectedValue.getDate());
}
public testYearFromLocalToNative() {
const expectedValue = 1980;
this.testView.year = expectedValue;
@@ -129,11 +124,10 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
const today = new Date(2016, 3, 15);
this.testView.year = today.getFullYear();
this.testView.month = today.getMonth();
const expectedValue = today.getDate();
this.testView.day = expectedValue;
const expectedDate = new Date(today.getFullYear(), today.getMonth(), expectedValue);
const expectedDate = new Date(today.getFullYear(), today.getMonth() - 1, expectedValue);
TKUnit.assertEqual(this.testView.date.getDate(), expectedDate.getDate(), "Getting Day from date property failed.");
TKUnit.assertEqual(this.testView.date.getMonth(), expectedDate.getMonth(), "Getting Month from date property failed.");
TKUnit.assertEqual(this.testView.date.getFullYear(), expectedDate.getFullYear(), "Getting Year from date property failed.");
@@ -146,7 +140,7 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
const expectedValue = today.getMonth();
this.testView.month = expectedValue;
const expectedDate = new Date(today.getFullYear(), expectedValue, today.getDate());
const expectedDate = new Date(today.getFullYear(), expectedValue - 1, today.getDate());
TKUnit.assertEqual(this.testView.date.getDate(), expectedDate.getDate(), "Getting Day from date property failed.");
TKUnit.assertEqual(this.testView.date.getMonth(), expectedDate.getMonth(), "Getting Month from date property failed.");
@@ -160,7 +154,7 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
const expectedValue = 1980;
this.testView.year = expectedValue;
const expectedDate = new Date(1980, current.getMonth(), current.getDate());
const expectedDate = new Date(1980, current.getMonth() - 1, current.getDate());
TKUnit.assertEqual(this.testView.date.getDate(), expectedDate.getDate(), "Getting Day from date property failed.");
TKUnit.assertEqual(this.testView.date.getMonth(), expectedDate.getMonth(), "Getting Month from date property failed.");
@@ -218,7 +212,7 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
datePickerTestsNative.setNativeDate(this.testView, today.getFullYear(), today.getMonth(), expectedValue);
const expectedDate = new Date(today.getFullYear(), today.getMonth(), expectedValue);
const expectedDate = new Date(today.getFullYear(), today.getMonth() - 1, expectedValue);
TKUnit.assertEqual(this.testView.date.getDate(), expectedDate.getDate(), "Getting Day from date property failed.");
TKUnit.assertEqual(this.testView.date.getMonth(), expectedDate.getMonth(), "Getting Month from date property failed.");
TKUnit.assertEqual(this.testView.date.getFullYear(), expectedDate.getFullYear(), "Getting Year from date property failed.");
@@ -230,7 +224,7 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
datePickerTestsNative.setNativeDate(this.testView, today.getFullYear(), expectedValue, today.getDate());
const expectedDate = new Date(today.getFullYear(), expectedValue, today.getDate());
const expectedDate = new Date(today.getFullYear(), expectedValue - 1, today.getDate());
TKUnit.assertEqual(this.testView.date.getDate(), expectedDate.getDate(), "Getting Day from date property failed.");
TKUnit.assertEqual(this.testView.date.getMonth(), expectedDate.getMonth(), "Getting Month from date property failed.");
TKUnit.assertEqual(this.testView.date.getFullYear(), expectedDate.getFullYear(), "Getting Year from date property failed.");
@@ -242,7 +236,7 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
const expectedValue = 1981;
datePickerTestsNative.setNativeDate(this.testView, expectedValue, today.getMonth(), today.getDate());
const expectedDate = new Date(expectedValue, today.getMonth(), today.getDate());
const expectedDate = new Date(expectedValue, today.getMonth() - 1, today.getDate());
TKUnit.assertEqual(this.testView.date.getDate(), expectedDate.getDate(), "Getting Day from date property failed.");
TKUnit.assertEqual(this.testView.date.getMonth(), expectedDate.getMonth(), "Getting Month from date property failed.");
TKUnit.assertEqual(this.testView.date.getFullYear(), expectedDate.getFullYear(), "Getting Year from date property failed.");
@@ -254,7 +248,7 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
const testDay = 24;
datePickerTestsNative.setNativeDate(this.testView, testYear, testMonth, testDay);
const expectedDate = new Date(testYear, testMonth, testDay);
const expectedDate = new Date(testYear, testMonth - 1, testDay);
TKUnit.assertEqual(this.testView.date.getDate(), expectedDate.getDate(), "Getting Day from date property failed.");
TKUnit.assertEqual(this.testView.date.getMonth(), expectedDate.getMonth(), "Getting Month from date property failed.");
TKUnit.assertEqual(this.testView.date.getFullYear(), expectedDate.getFullYear(), "Getting Year from date property failed.");