wix / react-native-calendars

React Native Calendar Components 🗓️ 📆
MIT License
9.57k stars 2.96k forks source link

Day names and dates not correctly rendered #2148

Closed igorjos closed 1 year ago

igorjos commented 1 year ago

Description

Calendar doesn't render properly. The day names and dates are not displayed to correspond.

E.g For January 1st 2023, the first day is Sunday. While calendar renders Monday to be first day.

Package.json "react": "18.1.0", "react-native": "0.70.6", "react-native-calendars": "^1.1293.0",

Implementation <Calendar firstDay={0} markedDates={markedDates} onDayPress={onDateSelection} theme={{ selectedDayBackgroundColor: colors._506571, selectedDayTextColor: colors._FFFFFF }} />

Expected Behavior

Day names and dates should be displayed properly. e.g 1st of January 2023 should be Sunday, 2nd of January 2023 should be Monday etc.

Observed Behavior

Render the default calendar, as stated in the example above. The marking of dates/days works well, the render of the calendar days (day names) and the corresponding date for the day is wrong.

No error messages, just wrong rendering.

Environment

Please run these commands in the project folder and fill in their results:

Happens on both iOS phone and simulator.

image

marcos-segantine commented 1 year ago

I was having the same issue..

marcos-segantine commented 1 year ago

Make sure you are filling in the fields dayNames and dayNamesShort inside LocaleConfig.locales in the correct order.

igorjos commented 1 year ago

@Marcos-Segantine thanks for the hint, but actually they are in correct order in the config, yet the displayed dates are not properly displayed. Here is my config:

import { LocaleConfig } from 'react-native-calendars';

LocaleConfig.locales['en'] = {
    monthNames: [
        'January',
        'February',
        'March',
        'April',
        'May',
        'June',
        'July',
        'August',
        'September',
        'October',
        'November',
        'December'
    ],
    monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
    dayNames: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
    dayNamesShort: ['M', 'T', 'W', 'T', 'F', 'S', 'S'],
    today: "Today"
};

LocaleConfig.defaultLocale = 'en';
igorjos commented 1 year ago

Ok found the issue, as stated in the documentation, the first day in the config must be Sunday, while as props firstDay={1} meaning that Monday will be rendered as first on screen.

//proper config setup of day names
{
    dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    dayNamesShort: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
}