|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
using System.Dynamic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using Connected.Annotations;
|
|
|
|
@ -14,11 +15,13 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
private const string format24Hours = "HH:mm";
|
|
|
|
|
private const string format12Hours = "hh:mm tt";
|
|
|
|
|
|
|
|
|
|
public TimePicker() : base(new DefaultConverter<TimeSpan?>())
|
|
|
|
|
|
|
|
|
|
public TimePicker() : base()
|
|
|
|
|
{
|
|
|
|
|
Converter.GetFunc = OnGet;
|
|
|
|
|
Converter.SetFunc = OnSet;
|
|
|
|
|
((DefaultConverter<TimeSpan?>)Converter).Format = format24Hours;
|
|
|
|
|
_timeFormat = format24Hours;
|
|
|
|
|
|
|
|
|
|
Converter = new LambdaConverter<TimeSpan?, string>((e) => OnSet(e), (e) => OnGet(e));
|
|
|
|
|
|
|
|
|
|
AdornmentIcon = Icons.Material.Filled.AccessTime;
|
|
|
|
|
AdornmentAriaLabel = "Open Time Picker";
|
|
|
|
|
}
|
|
|
|
@ -30,7 +33,7 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
|
|
|
|
|
var time = DateTime.Today.Add(timespan.Value);
|
|
|
|
|
|
|
|
|
|
return time.ToString(((DefaultConverter<TimeSpan?>)Converter).Format, Culture);
|
|
|
|
|
return time.ToString(_timeFormat, Culture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TimeSpan? OnGet(string value)
|
|
|
|
@ -38,7 +41,7 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
if (DateTime.TryParseExact(value, ((DefaultConverter<TimeSpan?>)Converter).Format, Culture, DateTimeStyles.None, out var time))
|
|
|
|
|
if (DateTime.TryParseExact(value, _timeFormat, Culture, DateTimeStyles.None, out var time))
|
|
|
|
|
{
|
|
|
|
|
return time.TimeOfDay;
|
|
|
|
|
}
|
|
|
|
@ -105,13 +108,10 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
|
|
|
|
|
_amPm = value;
|
|
|
|
|
|
|
|
|
|
if (Converter is DefaultConverter<TimeSpan?> defaultConverter && string.IsNullOrWhiteSpace(_timeFormat))
|
|
|
|
|
{
|
|
|
|
|
defaultConverter.Format = AmPm ? format12Hours : format24Hours;
|
|
|
|
|
}
|
|
|
|
|
_timeFormat = AmPm ? format12Hours : format24Hours;
|
|
|
|
|
|
|
|
|
|
Touched = true;
|
|
|
|
|
SetTextAsync(Converter.Set(_value), false).AndForget();
|
|
|
|
|
Modified = true;
|
|
|
|
|
SetTextAsync(Converter.Convert(_value), false).AndForget();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -129,11 +129,9 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_timeFormat = value;
|
|
|
|
|
if (Converter is DefaultConverter<TimeSpan?> defaultConverter)
|
|
|
|
|
defaultConverter.Format = _timeFormat;
|
|
|
|
|
|
|
|
|
|
Touched = true;
|
|
|
|
|
SetTextAsync(Converter.Set(_value), false).AndForget();
|
|
|
|
|
Modified = true;
|
|
|
|
|
SetTextAsync(Converter.Convert(_value), false).AndForget();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -155,7 +153,7 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
TimeIntermediate = time;
|
|
|
|
|
_value = time;
|
|
|
|
|
if (updateValue)
|
|
|
|
|
await SetTextAsync(Converter.Set(_value), false);
|
|
|
|
|
await SetTextAsync(Converter.Convert(_value), false);
|
|
|
|
|
UpdateTimeSetFromTime();
|
|
|
|
|
await TimeChanged.InvokeAsync(_value);
|
|
|
|
|
BeginValidate();
|
|
|
|
@ -170,9 +168,9 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
|
|
|
|
|
protected override Task StringValueChanged(string value)
|
|
|
|
|
{
|
|
|
|
|
Touched = true;
|
|
|
|
|
Modified = true;
|
|
|
|
|
// Update the time property (without updating back the Value property)
|
|
|
|
|
return SetTimeAsync(Converter.Get(value), false);
|
|
|
|
|
return SetTimeAsync(Converter.ConvertBack(value), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//The last line cannot be tested
|
|
|
|
|