0

I am creating a calendar for dance events. Different events go to different divs depending on their dates. This works perfectly on Desktop and Android devices, but it is failing in every iOS device I've tried it on; the events seem to go all in the same day or to random days. Like in this picture (this is how it should not look like screenshot of iOS emulator and this is how it should enter image description here)

I've ruled out that it is the CSS since I got rid of the CSS and the problem was persisting. I'm thinking it maybe has to do with the dates? Any hint will be appreciated.

Here is the link to the site just in case - http://www.juanitacalendar.de/

This is how I get the events from the database

 async componentDidMount() {
        let date = new Date();
        let from = date;
        from.setHours(0);
        from.setMinutes(0);
        from = from.toISOString();
        let to = new Date(
            date.getTime() + 14 * 24 * 60 * 60 * 1000
        ).toISOString();

        await firebase.auth().onAuthStateChanged(user => {
            console.log("hey user");
            this.setState({ isSignedIn: !!user });
        });
        await this.getEventsBetter(from, to);

        console.log("component did mount once");
    }

    getEventsBetter(from, to) {
        axios.get(`/getEventsBetter?from=${from}&to=${to}`).then(result => {
            this.setState({ events: result.data.data }, () => {
                console.log(
                    "i sure hope events appear here but BETTER",
                    this.state.events
                );
            });
        });
    }

Here I do all the date operations

render() {
        let date = new Date();
        let date1 = new Date();
        date1.setDate(date1.getDate() + 1);

        let day = days[date.getDay()];
        let day1 = days[date.getDay() + 1];
        let day2 = days[date.getDay() + 2];

        if (date.getDay() === date.getDay()) {
            day = "Today";
        }

        if (date.getDay() + 1 === date.getDay() + 1) {
            day1 = "Tomorrow";
        }

        function toSystemDate(date) {
            return new Date(
                `${date.getFullYear()}-${date.getMonth() +
                    1}-${date.getDate()} 22:00`
            );
        }

        let todayConvertedDate = toSystemDate(date).toString();
        let date1Converted = toSystemDate(date1).toString();
        let date2Converted = toSystemDate(date2).toString();



        console.log("USER", user);
        let indexe;
        return (
            <div className="main">

And here is the code that determines which evens should appear on "Today". Then it just repeats for each subsequent day.


                <div className="weeks">
                    {this.state.week === "this" && (
                        <div className="week1">
                            <div className="dayDiv">
                                <p className=" day">{day}</p>
                                <div className="eventsDiv">
                                    {this.state.events &&
                                        this.state.events
                                            .filter(data => {
                                                return (
                                                    todayConvertedDate ===
                                                        toSystemDate(
                                                            new Date(data.date0)
                                                        ).toString()
                                                );
                                            })
                                            .filter((data, index) => {
                                                console.log(
                                                    "look retriever",
                                                    index
                                                );
                                                indexe = index;
                                                if (
                                                    this.state.showMore ===
                                                    "true"
                                                ) {
                                                    return index < 30;
                                                } else {
                                                    return index < 3;

                                                }
                                            })
                                            .map(data => {
                                                return <Event data={data} />;
                                            })}

                                    {this.state.showMore=== "false" && indexe >= 3 && <div onClick={this.showMore}><p className="showMore">...</p></div>}
                                </div>
                            </div>
}

And the for "Tomorrow" (day1) and so on...

<div className="dayDiv">
    <p className=" day">{day1}</p>
    <div className="eventsDiv">
        {this.state.events &&
        this.state.events.map(data => {
            if ( date1Converted === toSystemDate( new Date(data.date0) ).toString() ) {
                return <Event data={data} />;
            }
        })}
    </div>
</div>
Jainil
  • 1,488
  • 1
  • 21
  • 26
Wilfredo Casas
  • 419
  • 2
  • 6
  • 14
  • See [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results). `new Date(\`${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} 22:00\`` produces a date like 2019-10-15 22:00, which is not a format supported by ECMAScript, so Safari–based browsers return an invalid date. – RobG Oct 23 '19 at 13:06
  • 1
    You should reduce your code to the minimum required to replicate the issue, see [*How to create a minimal, reproducible example*](https://stackoverflow.com/help/minimal-reproducible-example). – RobG Oct 23 '19 at 13:08
  • In what circumstance will `date.getDay() === date.getDay()` or `date.getDay() + 1 === date.getDay() + 1` ever be false? `date.getDay() + 1` will not give "tomorrow's" date when the date is the last day of the month. – RobG Oct 23 '19 at 13:11
  • `let from = date;` creates a second reference to the Date referenced by *date*, so all the changes to *from* are reflected in *date* (since they both reference the same Date instance). There are many issues with this code… – RobG Oct 23 '19 at 13:14

0 Answers0