Skip to content

DateTimePicker lose leading 0 in milliseconds when lose focus. #1796

Description

@konstantine2121

Error location

https://github.com/xceedsoftware/wpftoolkit/blob/master/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/DateTimeUpDown/Implementation/DateTimeParser.cs

DateTimeParser.cs

private static string ComputeDateTimeString( string dateTime, string format, DateTime currentDate, CultureInfo cultureInfo, bool autoClipTimeParts )

//Has error here.
string millisecondsPart = currentDate.Millisecond.ToString();

Case

If picker has dateTime value like this '28.04.2025 16:26:16.080'

millisecondsPart = "80";

We have lost leading 0.

in the end we have a result like this '28.04.2025 16:26:16.80'

'28.04.2025 16:26:16.80' == '28.04.2025 16:26:16.800'
'28.04.2025 16:26:16.80' != '28.04.2025 16:26:16.080'

Summary

Control lost focus and value changed.

Activity

  1. changed the title [-]DateTimePicker lose leading 0 in milliseconds while lose focus.[/-] [+]DateTimePicker lose leading 0 in milliseconds when lose focus.[/+] on Apr 28, 2025
  2. konstantine2121 commented on Apr 28, 2025

    @konstantine2121
    Author

    How to reproduce this bug case

    Set control Format property value = "dd.MM.yyyy HH:mm:ss" (No milliseconds in format!)

    And the bound property from the ViewModel needs to have milliseconds in its value.

  3. XceedBoucherS commented on Apr 30, 2025

    @XceedBoucherS
    Collaborator

    Hi,

    Thank you for reporting this.

    Here's a quick fix:
    Go in file: Xceed.Wpf.Toolkit/DateTimeUpDown/Implementation/DateTimeParser.cs
    In method : ComputeDateTimeString()
    near the end, and add
    while( millisecondsPart.Length < 3 )
    {
    millisecondsPart = "0" + millisecondsPart;
    }
    just before the line:
    time += "." + millisecondsPart;

    This will make sure 80ms is not transformed in 800ms in the DateTime.TryParse() call.

    This will be fixed in a future release.
    Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions