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

Even if initialTime is now, it is rounded off to the nearest past hour #6

Open
AyushmanChatterjee opened this issue Jul 6, 2020 · 1 comment

Comments

@AyushmanChatterjee
Copy link

Hi @longphanmn ,

First of all thank you for creating this package. It is very useful.

Only problem is while setting initial time to current datetime, the start time is picked as nearest past hour, if a user does not select a time manually. e.g. If start time is 11:40, after tapping on Done, picked start time is 11:00.

I am using the following to round the minutes to the nearest interval. Please use it if you think it can be helpful to fix this issue. If you see any problems, let me know.

Solution:

// Remove minutes and seconds to prevent exception of cupertino picker: initial minute is not divisible by minute interval
    int initialStartTimeMinute =
        (initialStartTime.minute / interval).round() * interval;
    initialStartTime = initialStartTime.subtract(Duration(
        minutes: initialStartTime.minute, seconds: initialStartTime.second));
    initialStartTime =
        initialStartTime.add(Duration(minutes: initialStartTimeMinute));

    if (initialEndTime == null) {
      initialEndTime = initialStartTime.add(Duration(
          days: mode == DateTimeRangePickerMode.time ? 0 : 1,
          hours: mode == DateTimeRangePickerMode.time ? 2 : 0));
    }

    int initialEndTimeMinute =
        (initialEndTime.minute / interval).round() * interval;
    initialEndTime = initialEndTime.subtract(Duration(
        minutes: initialEndTime.minute, seconds: initialEndTime.second));
    initialEndTime =
        initialEndTime.add(Duration(minutes: initialEndTimeMinute));
@BenjiFarquhar
Copy link

This is working for me, thanks. I just added "!" to all initialStartTime and initialEndTime after the null checks.

So others are aware, this fixes a (in my opinion - bug) where the initialStartTime and initialEndTime removes the minutes when using DateTimeRangePicker(initialStartTime: x, initialEndTime: y).showTime()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants