Skip to content

Commit

Permalink
fix: minimal weekday abbreviations (#1106)
Browse files Browse the repository at this point in the history
In this change, we use the complete minimal weekday abbreviations for all locales from moment.js in the Calendar component. There isn't a recommended length for weekday name abbreviations in the Fiori design guidelines for datepicker: https://experience.sap.com/fiori-design-web/date-picker/
  • Loading branch information
prsdthkr committed Jun 25, 2020
1 parent 860e3cb commit 8c0163a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ class Calendar extends Component {

generateWeekdays = () => {
const weekDays = [];
const daysName = moment.localeData(this.props.locale).weekdaysMin().map(day => day.charAt(0));
const daysName = moment.localeData(this.props.locale).weekdaysMin();
const shiftedDaysName = this.shiftDays(this.normalizedWeekdayStart(), daysName);

for (let index = 0; index < 7; index++) {
Expand Down
18 changes: 9 additions & 9 deletions src/Calendar/Calendar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,63 +464,63 @@ describe('<Calendar />', () => {
wrapper.setState({ currentDateDisplayed: date });
const firstWeekday = wrapper.find('th.fd-calendar__item .fd-calendar__text').first().text();
const firstDate = wrapper.find('td').first().text();
expect(firstWeekday).toBe('S');
expect(firstWeekday).toBe('Su');
expect(firstDate).toBe('31'); // May 31, 2020
});
test('should render weekday start as Monday', () => {
const wrapper = mount(weekdayStart(1));
wrapper.setState({ currentDateDisplayed: date });
const firstWeekday = wrapper.find('th.fd-calendar__item .fd-calendar__text').first().text();
const firstDate = wrapper.find('td').first().text();
expect(firstWeekday).toBe('M');
expect(firstWeekday).toBe('Mo');
expect(firstDate).toBe('1'); // June 1, 2020
});
test('should render weekday start as Tuesday', () => {
const wrapper = mount(weekdayStart(2));
wrapper.setState({ currentDateDisplayed: date });
const firstWeekday = wrapper.find('th.fd-calendar__item .fd-calendar__text').first().text();
const firstDate = wrapper.find('td').first().text();
expect(firstWeekday).toBe('T');
expect(firstWeekday).toBe('Tu');
expect(firstDate).toBe('26'); // May 26, 2020 because our starting weekday is now after the first day of the month
});
test('should render weekday start as Wednesday', () => {
const wrapper = mount(weekdayStart(3));
wrapper.setState({ currentDateDisplayed: date });
const firstWeekday = wrapper.find('th.fd-calendar__item .fd-calendar__text').first().text();
const firstDate = wrapper.find('td').first().text();
expect(firstWeekday).toBe('W');
expect(firstWeekday).toBe('We');
expect(firstDate).toBe('27'); // May 27, 2020
});
test('should render weekday start as Thursday', () => {
const wrapper = mount(weekdayStart(4));
wrapper.setState({ currentDateDisplayed: date });
const firstWeekday = wrapper.find('th.fd-calendar__item .fd-calendar__text').first().text();
const firstDate = wrapper.find('td').first().text();
expect(firstWeekday).toBe('T');
expect(firstWeekday).toBe('Th');
expect(firstDate).toBe('28'); // May 28, 2020
});
test('should render weekday start as Friday', () => {
const wrapper = mount(weekdayStart(5));
wrapper.setState({ currentDateDisplayed: date });
const firstWeekday = wrapper.find('th.fd-calendar__item .fd-calendar__text').first().text();
const firstDate = wrapper.find('td').first().text();
expect(firstWeekday).toBe('F');
expect(firstWeekday).toBe('Fr');
expect(firstDate).toBe('29'); // May 29, 2020
});
test('should render weekday start as Saturday', () => {
const wrapper = mount(weekdayStart(6));
wrapper.setState({ currentDateDisplayed: date });
const firstWeekday = wrapper.find('th.fd-calendar__item .fd-calendar__text').first().text();
const firstDate = wrapper.find('td').first().text();
expect(firstWeekday).toBe('S');
expect(firstWeekday).toBe('Sa');
expect(firstDate).toBe('30'); // May 30, 2020
});
test('should render even when number as a string is passed in', () => {
const wrapper = mount(weekdayStart('6'));
wrapper.setState({ currentDateDisplayed: date });
const firstWeekday = wrapper.find('th.fd-calendar__item .fd-calendar__text').first().text();
const firstDate = wrapper.find('td').first().text();
expect(firstWeekday).toBe('S');
expect(firstWeekday).toBe('Sa');
expect(firstDate).toBe('30'); // May 30, 2020
});
test('should default to Sunday view when prop is not a number or a number as a string', () => {
Expand All @@ -530,7 +530,7 @@ describe('<Calendar />', () => {
const firstWeekday = wrapper.find('th.fd-calendar__item .fd-calendar__text').first().text();
const firstDate = wrapper.find('td').first().text();
expect(consoleSpy).toHaveBeenCalled();
expect(firstWeekday).toBe('S');
expect(firstWeekday).toBe('Su');
expect(firstDate).toBe('31'); // May 31, 2020
});
});
Expand Down

0 comments on commit 8c0163a

Please sign in to comment.