react-native-calendars icon indicating copy to clipboard operation
react-native-calendars copied to clipboard

react-native-calendars moved 1 day forward

Open mparkhomenko opened this issue 6 years ago • 18 comments

At the time of creating the post, it was Friday 30th. For some reason, my calendar displays this day as Saturday:

<Calendar style={{width: Dimensions.get('screen').width - 10}} theme={{ selectedDayBackgroundColor: '#00adf5', selectedDayTextColor: '#ffffff', dotColor: '#00adf5', }} onDayPress={this.onDaySelect} markedDates={this.state.markedDates} markingType="single" minDate={minDate} maxDate={maxDate} disableAllTouchEventsForDisabledDays={true} />

Screen Shot 2020-10-30 at 16 59 43

mparkhomenko avatar Oct 30 '20 14:10 mparkhomenko

This is likely a UTC issue where you're local time is now "tomorrow" in UTC. You should set the current property to today's date string. In my own, I use it like this:

const date = new Date();

<Calendar 
    current={date.toLocaleDateString()}
    ... // other props
/>

lostchopstik avatar Oct 30 '20 23:10 lostchopstik

@lostchopstik Thank you for your help, but It doesn't work for me :( console.log(new Date().toLocaleDateString()); shows 10/31/2020 (current date). console.log(new Date()); also shows current date (Sat Oct 31 2020 10:41:14 GMT+0300 (Moscow Standard Time)), but in calendar I also see incorrect variant.

Screen Shot 2020-10-31 at 10 46 21

mparkhomenko avatar Oct 31 '20 07:10 mparkhomenko

I have faced same issues. Please help me

jaiminp-nimblechapps avatar Nov 06 '20 03:11 jaiminp-nimblechapps

@mparkhomenko Please added parameters firstDay={6}.

jaiminp-nimblechapps avatar Nov 09 '20 03:11 jaiminp-nimblechapps

@jaiminp-nimblechapps It didn't help :( Do you have other variants?

mparkhomenko avatar Nov 09 '20 06:11 mparkhomenko

@mparkhomenko Go to this file location

react-native-calenders -> src -> calendar -> header -> index.js

and changed

let weekDaysNames = weekDayNames(this.props.firstDay);
to 
let weekDaysNames = weekDayNames(6);

I have faced the same issue I have resolved this issue from the above solution

jaiminp-nimblechapps avatar Nov 09 '20 11:11 jaiminp-nimblechapps

@jaiminp-nimblechapps thank you!!!

mparkhomenko avatar Nov 09 '20 19:11 mparkhomenko

@mparkhomenko Glad to help!!!!

jaiminp-nimblechapps avatar Nov 10 '20 03:11 jaiminp-nimblechapps

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 08 '21 03:02 stale[bot]

this solution make sunday first day of week. Its not suitable for me and i try to read typescript Add this:

firstDay={1} with https://github.com/wix/react-native-calendars/issues/1319#issuecomment-723943875

After this first day of week is monday and day forward fixed.

zaferatli avatar May 07 '22 07:05 zaferatli

I've came across with the same problem in Agenda component. I've added firstDay=1, and didn't change the order of the short day names. But now, date of days are incorrect. Today is 1st of September Thursday but It looks like Friday in weekly view. How can i solve this?

cwtaras avatar Sep 01 '22 14:09 cwtaras

I've came across with the same problem in Agenda component. I've added firstDay=1, and didn't change the order of the short day names. But now, date of days are incorrect. Today is 1st of September Thursday but It looks like Friday in weekly view. How can i solve this?

I think I have same issue in Turkish. Simulator Screen Shot - iPhone 14 Pro - 2023-01-05 at 13 57 01

alperkilickaya avatar Jan 05 '23 11:01 alperkilickaya

@ cwtaras I think I found a solution for Agenda wrong day issue with locale config for @1.1293.0 version.

Go to; node_modules->react-native-calendars->src->agenda->reservation-list->reservation.js

Change; {dayNames ? dayNames[date.getDay()] : undefined} (should be line 64) to {dayNames ? dayNames[date.getDay()-1] : undefined}

Also apply same approach for agenda as mentioned above for calendar; Go to; node_modules->react-native-calendars->src->agenda->index.js

Change; <WeekDaysNames firstDay={this.props.firstDay} style={this.style.dayHeader}/> to <WeekDaysNames firstDay={6} style={this.style.dayHeader}/>

alperkilickaya avatar Jan 05 '23 12:01 alperkilickaya

let weekDaysNames = weekDayNames(this.props.firstDay);

why 6?

fherrera7850 avatar Aug 05 '23 13:08 fherrera7850

I am having this issue in production can we please have a fix that works for all timezones like a property or something ☺. For example for people in Poland and Indonesia they say the Calendar day is a day forward from phone date . @yakirza17 @yuvalsho @Inbal-Tish

https://stackoverflow.com/questions/64609833/react-native-calendars-moved-1-day-forward

Give me a link i will donate for this to be fixed ☺

goxr3plus avatar Nov 01 '23 13:11 goxr3plus

I had the same issue and it turns out it is due to the way the .getDay() function is defined. For some reason it is not Mon-Sun but Sun-Sat. So Sunday is 0 and Saturday is 6, this makes it seem like there is an issue with a timeshift if you expect Monday to be 0 and Sunday 6. See the docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay

Since I define the weekday names in a separate file I don't want to use the Sun-Sat format as I think it is counter intuitive. I simply shift the days using this function:

function dayRangeShift(dayIndex:number){
        return (dayIndex+6)%7;
    }

agruenb avatar Mar 02 '24 09:03 agruenb

@ cwtaras I think I found a solution for Agenda wrong day issue with locale config for @1.1293.0 version.

Go to; node_modules->react-native-calendars->src->agenda->reservation-list->reservation.js

Change; {dayNames ? dayNames[date.getDay()] : undefined} (should be line 64) to {dayNames ? dayNames[date.getDay()-1] : undefined}

Also apply same approach for agenda as mentioned above for calendar; Go to; node_modules->react-native-calendars->src->agenda->index.js

Change; <WeekDaysNames firstDay={this.props.firstDay} style={this.style.dayHeader}/> to <WeekDaysNames firstDay={6} style={this.style.dayHeader}/>

Tried this solution on @1.1305.0 version, and didn't work.

But logging around shows me that for some reason, at first moment the day is right , and suddenly it re-renders and stay on future date.

image

image

image

Anyone had more luck on finding an alternative solution? :/

PedroW21 avatar Aug 30 '24 17:08 PedroW21

You don't need to intervene directly in the package. Start the day list you provide from Sunday and let firstDay={1}. This solved my problem.

gonca-gul avatar Mar 14 '25 12:03 gonca-gul