Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/app/ui/date-picker/date-picker-tests-native.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,13 +25,13 @@ 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 {
datePicker.android.updateDate(datePicker.android.getYear(), datePicker.android.getMonth(), value);
}

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);
}
6 changes: 3 additions & 3 deletions tests/app/ui/date-picker/date-picker-tests-native.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down
22 changes: 8 additions & 14 deletions tests/app/ui/date-picker/date-picker-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand All @@ -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.");
Expand All @@ -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.");
Expand All @@ -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.");
Expand Down Expand Up @@ -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.");
Expand All @@ -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.");
Expand All @@ -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.");
Expand All @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/date-picker/date-picker-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ yearProperty.register(DatePickerBase);

export const monthProperty = new Property<DatePickerBase, number>({
name: "month",
defaultValue: defaultDate.getMonth(),
defaultValue: defaultDate.getMonth() + 1,
valueConverter: v => parseInt(v),
});
monthProperty.register(DatePickerBase);
Expand Down
21 changes: 4 additions & 17 deletions tns-core-modules/ui/date-picker/date-picker.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function initializeDateChangedListener(): void {
dateChanged = true;
}

if (month !== owner.month) {
monthProperty.nativeValueChange(owner, month);
if (month !== (owner.month - 1)) {
monthProperty.nativeValueChange(owner, month + 1);
dateChanged = true;
}

Expand Down Expand Up @@ -77,42 +77,29 @@ export class DatePicker extends DatePickerBase {
private updateNativeDate(): void {
const nativeView = this.nativeViewProtected;
const year = typeof this.year === "number" ? this.year : nativeView.getYear();
const month = typeof this.month === "number" ? this.month : nativeView.getMonth();
const month = typeof this.month === "number" ? this.month - 1 : nativeView.getMonth();
const day = typeof this.day === "number" ? this.day : nativeView.getDayOfMonth();
this.date = new Date(year, month, day);
}

[yearProperty.getDefault](): number {
return this.nativeViewProtected.getYear();
}
[yearProperty.setNative](value: number) {
if (this.nativeViewProtected.getYear() !== value) {
this.updateNativeDate();
}
}

[monthProperty.getDefault](): number {
return this.nativeViewProtected.getMonth();
}
[monthProperty.setNative](value: number) {
if (this.nativeViewProtected.getMonth() !== value) {
if (this.nativeViewProtected.getMonth() !== (value - 1)) {
this.updateNativeDate();
}
}

[dayProperty.getDefault](): number {
return this.nativeViewProtected.getDayOfMonth();
}
[dayProperty.setNative](value: number) {
if (this.nativeViewProtected.getDayOfMonth() !== value) {
this.updateNativeDate();
}
}

[dateProperty.getDefault](): Date {
const nativeView = this.nativeViewProtected;
return new Date(nativeView.getYear(), nativeView.getMonth(), nativeView.getDayOfMonth());
}
[dateProperty.setNative](value: Date) {
const nativeView = this.nativeViewProtected;
if (nativeView.getDayOfMonth() !== value.getDay()
Expand Down
25 changes: 6 additions & 19 deletions tns-core-modules/ui/date-picker/date-picker.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,18 @@ export class DatePicker extends DatePickerBase {
return this.nativeViewProtected;
}

[yearProperty.getDefault](): number {
return this.nativeViewProtected.date.getFullYear();
}
[yearProperty.setNative](value: number) {
this.date = new Date(value, this.month, this.day);
this.date = new Date(value, this.month - 1, this.day);
}

[monthProperty.getDefault](): number {
return this.nativeViewProtected.date.getMonth();
}
[monthProperty.setNative](value: number) {
this.date = new Date(this.year, value, this.day);
this.date = new Date(this.year, value - 1, this.day);
}

[dayProperty.getDefault](): number {
return this.nativeViewProtected.date.getDay();
}
[dayProperty.setNative](value: number) {
this.date = new Date(this.year, this.month, value);
this.date = new Date(this.year, this.month - 1, value);
}

[dateProperty.getDefault](): Date {
return this.nativeViewProtected.date;
}
[dateProperty.setNative](value: Date) {
const picker = this.nativeViewProtected;
const comps = ios.getter(NSCalendar, NSCalendar.currentCalendar).componentsFromDate(NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitDay, picker.date);
Expand Down Expand Up @@ -108,9 +96,8 @@ class UIDatePickerChangeHandlerImpl extends NSObject {
dateChanged = true;
}

const jsMonth = comps.month - 1;
if (jsMonth !== owner.month) {
monthProperty.nativeValueChange(owner, jsMonth);
if (comps.month !== owner.month) {
monthProperty.nativeValueChange(owner, comps.month);
dateChanged = true;
}

Expand All @@ -120,7 +107,7 @@ class UIDatePickerChangeHandlerImpl extends NSObject {
}

if (dateChanged) {
dateProperty.nativeValueChange(owner, new Date(comps.year, jsMonth, comps.day));
dateProperty.nativeValueChange(owner, new Date(comps.year, comps.month - 1, comps.day));
}
}

Expand Down