Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialTime is not working correctly #66

Open
GaoMax opened this issue Mar 27, 2021 · 5 comments
Open

initialTime is not working correctly #66

GaoMax opened this issue Mar 27, 2021 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@GaoMax
Copy link

GaoMax commented Mar 27, 2021

Describe the bug
I use a function to determine the initialTime for the DayView, but in some cases the DayView just ignores the initialTime.
For example: the function returns HourMinute {"hour":6,"minute":45}, but the DayView initializes with 7:45.
The same function worked flawlessly with the previous initalHour build.

Testen on Android & iOS, using devices and simulators.

@GaoMax GaoMax added the bug Something isn't working label Mar 27, 2021
@Skyost
Copy link
Owner

Skyost commented Mar 27, 2021

Would it be possible to get a code snippet ?

@GaoMax
Copy link
Author

GaoMax commented Mar 27, 2021

Sure! Thanks for the help, really like your project.

return DayView(
          controller: dayViewController,
          date: DateTime(
              DateTime.now().add(Duration(days: i)).year,
              DateTime.now().add(Duration(days: i)).month,
              DateTime.now().add(Duration(days: i)).day),
          events: getEvents(i),
          initialTime: getInitialTime(i),
          userZoomable: false,
          dayBarStyle: DayBarStyle(
            color: _darkMode ? Colors.grey[850] : Colors.grey[50],
            textAlignment: Alignment.centerLeft,
            textStyle: Style.smallTextStyle,
            dateFormatter: formatDate,
          ),
          style: DayViewStyle(
            backgroundColor: _darkMode ? Colors.grey[850] : Colors.grey[50],
            backgroundRulesColor:
                _darkMode ? Colors.grey[50] : Colors.grey[400],
            hourRowHeight: 100,
            currentTimeCircleColor: Style.primaryColor,
            currentTimeRuleColor: Style.primaryColor,
            headerSize: 0,
          ),
          hoursColumnStyle: HoursColumnStyle(
            color: _darkMode ? Colors.grey[850] : Colors.grey[50],
            textStyle: TextStyle(
              color: _darkMode
                  ? Style.darkModeTextColor
                  : Style.brightModeTextColor,
            ),
          ),
        );
  HourMinute getInitialTime(i) {
    DateTime date = DateTime(
        DateTime.now().add(Duration(days: i)).year,
        DateTime.now().add(Duration(days: i)).month,
        DateTime.now().add(Duration(days: i)).day);
    DateTime chosen = date.add(Duration(hours: 23, minutes: 59));
    bool b = false;
    for (Termin t in widget.userData.termine.getAll()) {
      //if (t.status != Termin.RED) {
      if (t.startTime.year == date.year &&
          t.startTime.month == date.month &&
          t.startTime.day == date.day) {
        if (t.startTime.isBefore(chosen)) {
          chosen = t.startTime;
          b = true;
        }
      }
      //}
    }
    if (!b) {
      chosen = date.add(Duration(minutes: 45));
    } else {
      chosen = chosen.subtract(Duration(minutes: 15));
    }

    print(HourMinute.fromDateTime(dateTime: chosen));
    return HourMinute.fromDateTime(dateTime: chosen);
  }

@Skyost
Copy link
Owner

Skyost commented Mar 27, 2021

Thanks ! Would it be possible to also know how you're setting the initialTime value (Provider, setState, ...) ?

@GaoMax
Copy link
Author

GaoMax commented Mar 27, 2021

I'm using it inside a PageView, but I believe I've found the bug. It's due to daylight saving time (tonight). But I can't seem to figure out how to prevent it, I'm using UTC for all my calculations and they are right. I believe that the dayView somehow accounts for daylight saving time, resulting in {"hour":6,"minute":45}, being shown as 7:45.

@GaoMax GaoMax closed this as completed Mar 27, 2021
@GaoMax GaoMax reopened this Mar 27, 2021
@Skyost
Copy link
Owner

Skyost commented Mar 29, 2021

I believe that the dayView somehow accounts for daylight saving time, resulting in {"hour":6,"minute":45}, being shown as 7:45.

You're right. I have to figure out what I can do to fix this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants