Skip to content

Commit

Permalink
Centralize time extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez committed Mar 18, 2021
1 parent ef7fb50 commit 856738d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;

namespace Microsoft.Maui
{
Expand All @@ -12,17 +13,16 @@ public static string ToFormattedString(this ITimePicker timePicker)
return time.ToFormattedString(format);
}

public static string ToFormattedString(this TimeSpan time, string format)
public static string ToFormattedString(this TimeSpan time, string format, CultureInfo? cultureInfo = null)
{
cultureInfo ??= CultureInfo.CurrentCulture;

if (string.IsNullOrEmpty(format))
{
var timeFormat = "t";
return DateTime.Today.Add(time).ToString(timeFormat);
}
else
{
return DateTime.Today.Add(time).ToString(format);
format = cultureInfo.DateTimeFormat.ShortTimePattern;
}

return DateTime.Today.Add(time).ToString(format, cultureInfo);
}
}
}
36 changes: 0 additions & 36 deletions src/Core/src/Platform/iOS/TimeExtensions.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/Core/src/Platform/iOS/TimePickerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public static void UpdateTime(this MauiTimePicker nativeTimePicker, ITimePicker

if (string.IsNullOrEmpty(timePicker.Format))
{
string timeformat = cultureInfo.DateTimeFormat.ShortTimePattern;
NSLocale locale = new NSLocale(cultureInfo.TwoLetterISOLanguageName);

if (picker != null)
Expand Down

0 comments on commit 856738d

Please sign in to comment.