Skip to content

initialTime is not working correctly #66

Open

Description

@GaoMax

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.

Activity

  1. added
    bug
    on Mar 27, 2021
  2. Skyost commented on Mar 27, 2021

    @Skyost
    Owner

    Would it be possible to get a code snippet ?

  3. GaoMax commented on Mar 27, 2021

    @GaoMax
    Author

    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);
      }
    
  4. Skyost commented on Mar 27, 2021

    @Skyost
    Owner

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

  5. GaoMax commented on Mar 27, 2021

    @GaoMax
    Author

    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.

  6. reopened this on Mar 27, 2021
  7. Skyost commented on Mar 29, 2021

    @Skyost
    Owner

    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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions