question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TimePicker always returns today

See original GitHub issue

Hi,

I have found an issue with the way I would like to use the TimePicker control, which shows up if you are trying to link a DatePicker (MyVariable bound to SelectedDate) and a TimePicker (MyVariable bound to SelectedTime) to manipulate the different date/time portions of the same DateTime property.

If you change the date picker to an alternative date, then select the TimePicker button to show the popup menu it eventually hits the SetSelectedTime() Function and because the text box already contains a string value representing the currently set time, it parses just the time string and thus will always return today as it has no date element to parse.

Call stack: TogglePopup() => SetSelectedTime()

Existing Function:

private void SetSelectedTime(bool beCautious = false)
{
    if (!string.IsNullOrEmpty(_textBox?.Text))
    {
        ParseTime(_textBox.Text, t =>
        {
            if (!beCautious || DateTimeToString(t) == _textBox.Text)
                SetCurrentValue(SelectedTimeProperty, t);
        });
    }
    else
    {
        SetCurrentValue(SelectedTimeProperty, null);
    }
}

Maybe a check to see if the SelectedTime property is already set would be useful?

Suggested fix:

private void SetSelectedTime(bool beCautious = false)
{
    if(SelectedTime == null)
    {
        if (!string.IsNullOrEmpty(_textBox?.Text))
        {
            ParseTime(_textBox.Text, t =>
            {
                if (!beCautious || DateTimeToString(t) == _textBox.Text)
                    SetCurrentValue(SelectedTimeProperty, t);
            });
        }
        else
        {
            SetCurrentValue(SelectedTimeProperty, null);
        }
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
greuelpiratcommented, May 5, 2020

This seems to be already fixed with #1691

0reactions
Keboocommented, Dec 16, 2019

@MichelMichels Initially, am not sure switching to a TimeSpan is the right option (would love to hear other people feedback too). As I see it, the benefits of a TimeSpan are that it doesn’t have those messy date related properties. The downside would be that a TimeSpan represents a duration of time, not a single point in time. Most people implicitly assume a fixed starting offset and add the timespan to it (00:00:00 + time span = point in time). The other drawback is we then need to handle un-usual points in time, such as TimeSpan greater than 24 hours, or timespan that land on daylight savings time.

IMO, I think DateTime is a bit more clear that we are picking an individual point in time rather than a duration, so I like it better. Again, open to hearing other opinions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android TimePicker returning the current minute instead of ...
The timepicker is intialized to the current time, which is fine. when i select a new time the hours are correct but the...
Read more >
TimePicker .value() not returning the expected date
Hi Jeff, The reason for current behavior is that the timePicker gets only the time part of the selected date and apply it...
Read more >
Solved: Script Field - Date Time Picker always returns $da...
Select 'Date Time Range picker' from the 'Search Template' drop-down and submit the form.
Read more >
TimePicker.Instant's date is inconsistent between iOS and ...
Now on Android is from a date in 1970 but on iOS it is from today's date. ... the time picker instant on...
Read more >
Xamarin.Forms TimePicker
Today property returns a DateTime indicating the current date, but with a time of midnight. If the timer time has already passed today,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found