Skip to content

Commit

Permalink
✨ Numeric Date Entry - enable custom culture
Browse files Browse the repository at this point in the history
  • Loading branch information
JosselinTILLAY committed Mar 18, 2024
1 parent 35750c4 commit 4a9c9ab
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions Smartway.UiComponent/Inputs/NumericDateEntry.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public ICommand ErrorCommand
set => SetValue(ErrorCommandProperty, value);
}

private CultureInfo _culture;
public CultureInfo Culture
{
get
{
if (_culture != null)
{
return _culture;
}

return CultureInfo.CurrentCulture;
}
set => _culture = value;
}

private List<Entry> _dateEntries;
public Entry DayEntry;
public Entry MonthEntry;
Expand Down Expand Up @@ -98,7 +113,7 @@ protected virtual DateTime GetFilledDate()
{
var day = int.Parse(DayEntry.Text);
var month = int.Parse(MonthEntry.Text);
var year = CultureInfo.CurrentCulture.Calendar.ToFourDigitYear(int.Parse(YearEntry.Text));
var year = Culture.Calendar.ToFourDigitYear(int.Parse(YearEntry.Text));

return new DateTime(year, month, day);
}
Expand Down Expand Up @@ -158,9 +173,9 @@ private void SetEntriesPlaceHolders()

private void SetDateTimePlaceholder()
{
DayEntry.Placeholder = DatePlaceholder.ToString("dd");
MonthEntry.Placeholder = DatePlaceholder.ToString("MM");
YearEntry.Placeholder = DatePlaceholder.ToString("yy");
DayEntry.Placeholder = DatePlaceholder.ToString("dd", Culture);
MonthEntry.Placeholder = DatePlaceholder.ToString("MM", Culture);
YearEntry.Placeholder = DatePlaceholder.ToString("yy", Culture);
}

protected virtual void SetFilledDate()
Expand All @@ -170,9 +185,9 @@ protected virtual void SetFilledDate()

var date = (DateTime)FilledDateTime;

DayEntry.Text = date.ToString("dd");
MonthEntry.Text = date.ToString("MM");
YearEntry.Text = date.ToString("yy");
DayEntry.Text = date.ToString("dd", Culture);
MonthEntry.Text = date.ToString("MM", Culture);
YearEntry.Text = date.ToString("yy", Culture);
}

private void SetEntriesPosition()
Expand Down Expand Up @@ -221,15 +236,13 @@ private void SetDefaultPlaceholder()

private bool IsDayMonthCalendar()
{
var calendarType =
CultureInfo.GetCultureInfo(CultureInfo.CurrentCulture.Name).DateTimeFormat.MonthDayPattern;
var calendarType = Culture.DateTimeFormat.MonthDayPattern;
return calendarType.IndexOf("d") < calendarType.IndexOf("M");
}

private bool IsYearsFirstCalendar()
{
var calendarType =
CultureInfo.GetCultureInfo(CultureInfo.CurrentCulture.Name).DateTimeFormat.YearMonthPattern;
var calendarType = Culture.DateTimeFormat.YearMonthPattern;
return calendarType.IndexOf("y") < calendarType.IndexOf("M");
}

Expand Down

0 comments on commit 4a9c9ab

Please sign in to comment.