Skip to content

Commit

Permalink
fix: date format bug (#936)
Browse files Browse the repository at this point in the history
* commit to the mm/dd/yyyy format by default and detail how to change this to the international style in the docs

* fix test
  • Loading branch information
mikerodonnell89 committed Jun 18, 2019
1 parent 51e3f7e commit 88acb58
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Expand Up @@ -4,6 +4,9 @@ <h2>Simple Date Picker</h2>
To select a date you will create a new object that contains the property date, whose value is a native JavaScript Date object. Then, using two-way binding syntax, set the selectedDay value to your new object.
Note that selecting a day (or range of days) in this manner will override any block/disable functions.
</description>
<description>
The default format for the input is MM/DD/YYYY. See the 'Formatting' section for details on how to change this.
</description>
<component-example [name]="'ex1'">
<fd-date-picker-single-example></fd-date-picker-single-example>
</component-example>
Expand Down
Expand Up @@ -13,7 +13,7 @@ export class DateFormatDashes extends DateFormatParser {
if (values[2] === 0) {
values[1] = 14;
}
return new Date(Number(values[0]), values[1] - 1, values[2]);
return new Date(Number(values[2]), values[1] - 1, values[0]);
}

public format(date: Date): string {
Expand All @@ -22,7 +22,7 @@ export class DateFormatDashes extends DateFormatParser {
monthStr = '0' + monthStr;
}

return date.getFullYear() + '-' + monthStr + '-' + date.getDate();
return date.getDate() + '-' + monthStr + '-' + date.getFullYear();
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/src/lib/calendar/format/date-parser.ts
Expand Up @@ -50,6 +50,6 @@ export class DateFormatParserDefault extends DateFormatParser {
* @param date Date object to convert to a string.
*/
public format(date: Date): string {
return date.toLocaleDateString();
return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
}
}
7 changes: 5 additions & 2 deletions library/src/lib/date-picker/date-picker.component.spec.ts
Expand Up @@ -68,11 +68,14 @@ describe('DatePickerComponent', () => {
};
component.type = 'single';
component.updateDatePickerInputHandler(d);
expect(component.inputFieldDate).toEqual(d.selectedDay.date.toLocaleDateString());
expect(component.inputFieldDate).toEqual(
(d.selectedDay.date.getMonth()) + 1 + '/' + d.selectedDay.date.getDate() + '/' + d.selectedDay.date.getFullYear());
component.type = 'range';
component.updateDatePickerInputHandler(d);
expect(component.inputFieldDate).toEqual(
d.selectedFirstDay.date.toLocaleDateString() + ' - ' + d.selectedLastDay.date.toLocaleDateString()
(d.selectedFirstDay.date.getMonth()) + 1 + '/' + d.selectedFirstDay.date.getDate() + '/' + d.selectedFirstDay.date.getFullYear()
+ ' - '
+ (d.selectedLastDay.date.getMonth() + 1) + '/' + d.selectedLastDay.date.getDate() + '/' + d.selectedLastDay.date.getFullYear()
);
});

Expand Down

0 comments on commit 88acb58

Please sign in to comment.