We are using military time format (HHmm) in our application and have faced with following bug.
We have fixed it by inheriting TimePicker as follows
public class TimePickerEx : TimePicker
{
protected override DateTime? ConvertTextToValue(string text)
{
// Fixed problem with incorrect parsing text with HHmm format
DateTime? result = base.ConvertTextToValue(text);
if (Value != null && result != null && Value.Value.Date != result.Value.Date)
{
result = Value.Value.Date.Add(result.Value.Subtract(result.Value.Date));
}
return result;
}
}
and using new TimePickerEx in control template of DateTimePicker
but it would be nice if you fix this problem in original TimePicker.
More deep investigation shows that problem is with DateTimeParser which internally is used in ConvertTextToValue, the parser parse text with HHmm format incorrectly.
Comments: ** Comment from web user: BoucherS **
We have fixed it by inheriting TimePicker as follows
public class TimePickerEx : TimePicker
{
protected override DateTime? ConvertTextToValue(string text)
{
// Fixed problem with incorrect parsing text with HHmm format
DateTime? result = base.ConvertTextToValue(text);
if (Value != null && result != null && Value.Value.Date != result.Value.Date)
{
result = Value.Value.Date.Add(result.Value.Subtract(result.Value.Date));
}
return result;
}
}
and using new TimePickerEx in control template of DateTimePicker
but it would be nice if you fix this problem in original TimePicker.
More deep investigation shows that problem is with DateTimeParser which internally is used in ConvertTextToValue, the parser parse text with HHmm format incorrectly.
Comments: ** Comment from web user: BoucherS **
hI,
This is happening because there is no known time separator. Usual time separators are :
```
" "
", "
"-"
"_"
"."
"/"
":"
```
We will look into this.
Thanks.