Skip to content

Commit 6738ae9

Browse files
authored
Nullable TimePicker (make Time nullable) (#27930)
* Nullable TimePicker.Time * Fix build errors, publicapi & sample * Update NotifiedPropertiesTests.cs * Update TimePickerUnitTest.cs * Put back shipped APIs
1 parent ee49a36 commit 6738ae9

34 files changed

+355
-286
lines changed

src/Compatibility/Core/src/Android/Renderers/TimePickerRenderer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void IPickerRenderer.OnClick()
140140
TimePicker view = Element;
141141
ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true);
142142

143-
_dialog = CreateTimePickerDialog(view.Time.Hours, view.Time.Minutes);
143+
_dialog = CreateTimePickerDialog(view.Time?.Hours ?? 0, view.Time?.Minutes ?? 0);
144144
_dialog.Show();
145145
}
146146

@@ -159,17 +159,17 @@ void OnCancelButtonClicked(object sender, EventArgs e)
159159
}
160160

161161
[PortHandler]
162-
void SetTime(TimeSpan time)
162+
void SetTime(TimeSpan? time)
163163
{
164164
if (String.IsNullOrEmpty(Element.Format))
165165
{
166166
var timeFormat = "t";
167-
EditText.Text = DateTime.Today.Add(time).ToString(timeFormat);
167+
EditText.Text = DateTime.Today.Add(time ?? TimeSpan.Zero).ToString(timeFormat);
168168
}
169169
else
170170
{
171171
var timeFormat = Element.Format;
172-
EditText.Text = DateTime.Today.Add(time).ToString(timeFormat);
172+
EditText.Text = DateTime.Today.Add(time ?? TimeSpan.Zero).ToString(timeFormat);
173173
}
174174

175175
Element.InvalidateMeasureNonVirtual(Internals.InvalidationTrigger.MeasureChanged);

src/Compatibility/Core/src/Windows/TimePickerRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void UpdateFont()
173173
[PortHandler]
174174
void UpdateTime()
175175
{
176-
Control.Time = Element.Time;
176+
Control.Time = Element.Time ?? TimeSpan.Zero;
177177
if (Element.Format?.Contains('H', StringComparison.Ordinal) == true)
178178
{
179179
Control.ClockIdentifier = "24HourClock";

src/Compatibility/Core/src/iOS/Renderers/TimePickerRenderer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void UpdateCharacterSpacing()
217217
[PortHandler]
218218
void UpdateTime()
219219
{
220-
_picker.Date = new DateTime(1, 1, 1).Add(Element.Time).ToNSDate();
220+
_picker.Date = new DateTime(1, 1, 1).Add(Element.Time ?? TimeSpan.Zero).ToNSDate();
221221
string iOSLocale = NSLocale.CurrentLocale.CountryCode;
222222
var cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures)
223223
.Where(c => c.Name.EndsWith("-" + iOSLocale)).FirstOrDefault();
@@ -228,12 +228,12 @@ void UpdateTime()
228228
{
229229
string timeformat = cultureInfos.DateTimeFormat.ShortTimePattern;
230230
NSLocale locale = new NSLocale(cultureInfos.TwoLetterISOLanguageName);
231-
Control.Text = DateTime.Today.Add(Element.Time).ToString(timeformat, cultureInfos);
231+
Control.Text = DateTime.Today.Add(Element.Time ?? TimeSpan.Zero).ToString(timeformat, cultureInfos);
232232
_picker.Locale = locale;
233233
}
234234
else
235235
{
236-
Control.Text = DateTime.Today.Add(Element.Time).ToString(Element.Format, cultureInfos);
236+
Control.Text = DateTime.Today.Add(Element.Time ?? TimeSpan.Zero).ToString(Element.Format, cultureInfos);
237237
}
238238

239239
if (Element.Format?.Contains('H', StringComparison.Ordinal) == true)

src/Controls/samples/Controls.Sample/Pages/Controls/TimePickerPage.xaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@
8787
Margin="6, 0"
8888
Style="{StaticResource IsFocusedTextStyle}"/>
8989
</HorizontalStackLayout>
90-
</VerticalStackLayout>
90+
<Label
91+
Text="Set to null"
92+
Style="{StaticResource Headline}"/>
93+
<TimePicker
94+
x:Name="NullTimePicker"
95+
Time="{x:Null}"/>
96+
<Button Text="Set to null" Clicked="SetTimePickerToNull" />
97+
<Button Text="Set to now" Clicked="SetTimePickerToNow" />
98+
</VerticalStackLayout>
9199
</views:BasePage.Content>
92100
</views:BasePage>

src/Controls/samples/Controls.Sample/Pages/Controls/TimePickerPage.xaml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public TimePickerPage()
1313
UpdateTimePickerBackground();
1414
}
1515

16-
void OnUpdateBackgroundButtonClicked(object sender, System.EventArgs e)
16+
void OnUpdateBackgroundButtonClicked(object sender, EventArgs e)
1717
{
1818
UpdateTimePickerBackground();
1919
}
2020

21-
void OnClearBackgroundButtonClicked(object sender, System.EventArgs e)
21+
void OnClearBackgroundButtonClicked(object sender, EventArgs e)
2222
{
2323
BackgroundTimePicker.Background = null;
2424
}
@@ -39,5 +39,15 @@ void UpdateTimePickerBackground()
3939
}
4040
};
4141
}
42+
43+
void SetTimePickerToNull(object sender, EventArgs e)
44+
{
45+
NullTimePicker.Time = null;
46+
}
47+
48+
void SetTimePickerToNow(object sender, EventArgs e)
49+
{
50+
NullTimePicker.Time = DateTime.Now.TimeOfDay;
51+
}
4252
}
4353
}

src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,6 @@ Microsoft.Maui.Controls.SearchBar.ReturnType.set -> void
221221
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
222222
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
223223
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
224-
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
224+
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
225+
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
226+
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?

src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,5 @@ override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.Comp
425425
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
426426
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.FormattedString! formattedString, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
427427
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.Span! span, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
428+
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
429+
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?

src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,6 @@ override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.Com
424424
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
425425
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
426426
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.FormattedString! formattedString, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
427-
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.Span! span, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
427+
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToNSAttributedString(this Microsoft.Maui.Controls.Span! span, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> Foundation.NSAttributedString!
428+
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
429+
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?

src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,6 @@ Microsoft.Maui.Controls.SearchBar.ReturnType.set -> void
216216
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
217217
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
218218
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
219-
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
219+
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
220+
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
221+
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?

src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,6 @@ override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.Com
224224
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
225225
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
226226
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.ToRunAndColorsTuples(this Microsoft.Maui.Controls.FormattedString! formattedString, Microsoft.Maui.IFontManager! fontManager, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> System.Collections.Generic.IEnumerable<System.Tuple<Microsoft.UI.Xaml.Documents.Run!, Microsoft.Maui.Graphics.Color!, Microsoft.Maui.Graphics.Color!>!>!
227-
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.UpdateInlines(this Microsoft.UI.Xaml.Controls.TextBlock! textBlock, Microsoft.Maui.IFontManager! fontManager, Microsoft.Maui.Controls.FormattedString! formattedString, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> void
227+
*REMOVED*static Microsoft.Maui.Controls.Platform.FormattedStringExtensions.UpdateInlines(this Microsoft.UI.Xaml.Controls.TextBlock! textBlock, Microsoft.Maui.IFontManager! fontManager, Microsoft.Maui.Controls.FormattedString! formattedString, double defaultLineHeight = 0, Microsoft.Maui.TextAlignment defaultHorizontalAlignment = Microsoft.Maui.TextAlignment.Start, Microsoft.Maui.Font? defaultFont = null, Microsoft.Maui.Graphics.Color? defaultColor = null, Microsoft.Maui.TextTransform defaultTextTransform = Microsoft.Maui.TextTransform.Default) -> void
228+
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
229+
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?

src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,6 @@ Microsoft.Maui.Controls.SearchBar.ReturnType.set -> void
215215
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
216216
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
217217
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
218-
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
218+
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
219+
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
220+
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?

src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,6 @@ Microsoft.Maui.Controls.SearchBar.ReturnType.set -> void
214214
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type! sourceType) -> bool
215215
override Microsoft.Maui.Controls.ListStringTypeConverter.CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) -> bool
216216
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object! value) -> object?
217-
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
217+
override Microsoft.Maui.Controls.ListStringTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type! destinationType) -> object?
218+
*REMOVED*Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan
219+
Microsoft.Maui.Controls.TimePicker.Time.get -> System.TimeSpan?

src/Controls/src/Core/TimePicker/TimePicker.Mapper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#nullable disable
2-
using System;
1+
using System;
32
using Microsoft.Maui.Controls.Compatibility;
43

54
namespace Microsoft.Maui.Controls

src/Controls/src/Core/TimePicker/TimePicker.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public partial class TimePicker : View, IFontElement, ITextElement, IElementConf
2020
public static readonly BindableProperty CharacterSpacingProperty = TextElement.CharacterSpacingProperty;
2121

2222
/// <summary>Bindable property for <see cref="Time"/>.</summary>
23-
public static readonly BindableProperty TimeProperty = BindableProperty.Create(nameof(Time), typeof(TimeSpan), typeof(TimePicker), new TimeSpan(0), BindingMode.TwoWay,
23+
public static readonly BindableProperty TimeProperty = BindableProperty.Create(nameof(Time), typeof(TimeSpan?), typeof(TimePicker), new TimeSpan(0), BindingMode.TwoWay,
2424
validateValue: (bindable, value) =>
2525
{
26-
var time = (TimeSpan)value;
27-
return time.TotalHours < 24 && time.TotalMilliseconds >= 0;
26+
var time = (TimeSpan?)value;
27+
return time is null || (time?.TotalHours < 24 && time?.TotalMilliseconds >= 0);
2828
},
2929
propertyChanged: TimePropertyChanged);
3030

@@ -70,9 +70,9 @@ public double CharacterSpacing
7070
}
7171

7272
/// <include file="../../docs/Microsoft.Maui.Controls/TimePicker.xml" path="//Member[@MemberName='Time']/Docs/*" />
73-
public TimeSpan Time
73+
public TimeSpan? Time
7474
{
75-
get { return (TimeSpan)GetValue(TimeProperty); }
75+
get { return (TimeSpan?)GetValue(TimeProperty); }
7676
set { SetValue(TimeProperty, value); }
7777
}
7878

@@ -157,7 +157,7 @@ void ITextElement.OnTextTransformChanged(TextTransform oldValue, TextTransform n
157157

158158
Font ITextStyle.Font => this.ToFont();
159159

160-
TimeSpan ITimePicker.Time
160+
TimeSpan? ITimePicker.Time
161161
{
162162
get => Time;
163163
set => SetValue(TimeProperty, value, SetterSpecificity.FromHandler);

src/Controls/tests/Core.UnitTests/NotifiedPropertiesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public override string DebugName
145145
new PropertyTestCase<TextCell, string> ("Detail", v => v.Detail, (v, o) => v.Detail = o, () => null, "Foo"),
146146
new PropertyTestCase<TextCell, Color> ("TextColor", v => v.TextColor, (v, o) => v.TextColor = o, () => null, new Color (0, 1, 0)),
147147
new PropertyTestCase<TextCell, Color> ("DetailColor", v => v.DetailColor, (v, o) => v.DetailColor = o, () => null, new Color (0, 1, 0)),
148-
new PropertyTestCase<TimePicker, TimeSpan> ("Time", v => v.Time, (v, o) => v.Time = o, () => default(TimeSpan), new TimeSpan (8, 0, 0)),
148+
new PropertyTestCase<TimePicker, TimeSpan?> ("Time", v => v.Time, (v, o) => v.Time = o, () => default(TimeSpan), new TimeSpan (8, 0, 0)),
149149
new PropertyTestCase<TimePicker, string> ("Format", v => v.Format, (v, o) => v.Format = o, () => "t", "T"),
150150
new PropertyTestCase<ViewCell, View> ("View", v => v.View, (v, o) => v.View = o, () => null, new View ()),
151151
new PropertyTestCase<WebView, WebViewSource> ("Source", v => v.Source, (v, o) => v.Source = o, () => null, new UrlWebViewSource { Url = "Foo" }),

src/Controls/tests/Core.UnitTests/TimePickerUnitTest.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ public void ZeroTimeIsValid()
4040
};
4141
}
4242

43+
[Fact]
44+
public void NullTimeIsValid()
45+
{
46+
var timePicker = new TimePicker
47+
{
48+
Time = null
49+
};
50+
51+
Assert.Null(timePicker.Time);
52+
}
53+
4354
[Fact]
4455
public void TestTimeSelected()
4556
{
@@ -57,7 +68,9 @@ public void TestTimeSelected()
5768
public static object[] TimeSpans = {
5869
new object[] { new TimeSpan (), new TimeSpan(9, 0, 0) },
5970
new object[] { new TimeSpan(9, 0, 0), new TimeSpan(17, 30, 0) },
60-
new object[] { new TimeSpan(23, 59, 59), new TimeSpan(0, 0, 0) }
71+
new object[] { new TimeSpan(23, 59, 59), new TimeSpan(0, 0, 0) },
72+
new object[] { new TimeSpan(23, 59, 59), null },
73+
new object[] { null, new TimeSpan(23, 59, 59) },
6174
};
6275

6376
public static IEnumerable<object[]> TimeSpansData()

src/Core/src/Core/ITimePicker.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
using System;
22

3-
namespace Microsoft.Maui
3+
namespace Microsoft.Maui;
4+
5+
/// <summary>
6+
/// Represents a <see cref="IView"/> that allows the user to select a time.
7+
/// </summary>
8+
public interface ITimePicker : IView, ITextStyle
49
{
510
/// <summary>
6-
/// Represents a View that allows the user to select a time.
11+
/// The format of the time to display to the user.
712
/// </summary>
8-
public interface ITimePicker : IView, ITextStyle
9-
{
10-
/// <summary>
11-
/// The format of the time to display to the user.
12-
/// </summary>
13-
string Format { get; }
13+
string Format { get; }
1414

15-
/// <summary>
16-
/// Gets the displayed time.
17-
/// </summary>
18-
TimeSpan Time { get; set; }
19-
}
15+
/// <summary>
16+
/// Gets or sets the selected time.
17+
/// </summary>
18+
TimeSpan? Time { get; set; }
2019
}

0 commit comments

Comments
 (0)