diff --git a/src/Ursa/Controls/DateTimePicker/Calendar.cs b/src/Ursa/Controls/DateTimePicker/Calendar.cs index 5b2e1f6..9aabeb0 100644 --- a/src/Ursa/Controls/DateTimePicker/Calendar.cs +++ b/src/Ursa/Controls/DateTimePicker/Calendar.cs @@ -1,4 +1,5 @@ using Avalonia; +using Avalonia.Collections; using Avalonia.Controls.Primitives; using Avalonia.Interactivity; @@ -12,8 +13,10 @@ public class Calendar: TemplatedControl get => GetValue(SelectedDateProperty); set => SetValue(SelectedDateProperty, value); } - - public static readonly StyledProperty FirstDayOfWeekProperty = AvaloniaProperty.Register(nameof(FirstDayOfWeek), DayOfWeek.Sunday); + + public static readonly StyledProperty FirstDayOfWeekProperty = + AvaloniaProperty.Register(nameof(FirstDayOfWeek), + defaultValue: DateTimeHelper.GetCurrentDateTimeFormatInfo().FirstDayOfWeek); public DayOfWeek FirstDayOfWeek { get => GetValue(FirstDayOfWeekProperty); @@ -26,4 +29,23 @@ public class Calendar: TemplatedControl get => GetValue(IsTodayHighlightedProperty); set => SetValue(IsTodayHighlightedProperty, value); } + + public static readonly StyledProperty?> DisabledDatesProperty = + AvaloniaProperty.Register?>( + nameof(DisabledDates)); + + public AvaloniaList? DisabledDates + { + get => GetValue(DisabledDatesProperty); + set => SetValue(DisabledDatesProperty, value); + } + + public static readonly StyledProperty DisabledDateRuleProperty = AvaloniaProperty.Register( + nameof(DisabledDateRule)); + + public IDateSelector? DisabledDateRule + { + get => GetValue(DisabledDateRuleProperty); + set => SetValue(DisabledDateRuleProperty, value); + } } \ No newline at end of file diff --git a/src/Ursa/Controls/DateTimePicker/CalendarDayButton.cs b/src/Ursa/Controls/DateTimePicker/CalendarDayButton.cs new file mode 100644 index 0000000..1a5d18e --- /dev/null +++ b/src/Ursa/Controls/DateTimePicker/CalendarDayButton.cs @@ -0,0 +1,8 @@ +using Avalonia.Controls; + +namespace Ursa.Controls; + +public class CalendarDayButton: Button +{ + +} \ No newline at end of file diff --git a/src/Ursa/Controls/DateTimePicker/DateRange.cs b/src/Ursa/Controls/DateTimePicker/DateRange.cs new file mode 100644 index 0000000..9bbb437 --- /dev/null +++ b/src/Ursa/Controls/DateTimePicker/DateRange.cs @@ -0,0 +1,36 @@ +namespace Ursa.Controls; + +/// +/// Represents a date range. It can be a single day or a range of days. The range is inclusive. +/// +public sealed record DateRange +{ + public DateRange(DateTime day) + { + Start = day.Date; + End = day.Date; + } + + public DateRange(DateTime start, DateTime end) + { + if (DateTime.Compare(end, start) >= 0) + { + Start = start.Date; + End = end.Date; + } + else + { + Start = start.Date; + End = start.Date; + } + } + + public DateTime Start { get; private set; } + public DateTime End { get; private set; } + + public bool Contains(DateTime? date) + { + if (date is null) return false; + return date >= Start && date <= End; + } +} \ No newline at end of file diff --git a/src/Ursa/Controls/DateTimePicker/DateTimeHelper.cs b/src/Ursa/Controls/DateTimePicker/DateTimeHelper.cs new file mode 100644 index 0000000..5869891 --- /dev/null +++ b/src/Ursa/Controls/DateTimePicker/DateTimeHelper.cs @@ -0,0 +1,17 @@ +using System.Globalization; + +namespace Ursa.Controls; + +internal static class DateTimeHelper +{ + public static DateTimeFormatInfo GetCurrentDateTimeFormatInfo() + { + if (CultureInfo.CurrentCulture.Calendar is GregorianCalendar) return CultureInfo.CurrentCulture.DateTimeFormat; + System.Globalization.Calendar? calendar = + CultureInfo.CurrentCulture.OptionalCalendars.OfType().FirstOrDefault(); + string cultureName = calendar is null ? CultureInfo.InvariantCulture.Name : CultureInfo.CurrentCulture.Name; + var dt = new CultureInfo(cultureName).DateTimeFormat; + dt.Calendar = calendar ?? new GregorianCalendar(); + return dt; + } +} \ No newline at end of file diff --git a/src/Ursa/Controls/DateTimePicker/IDateSelector.cs b/src/Ursa/Controls/DateTimePicker/IDateSelector.cs new file mode 100644 index 0000000..79ec2ef --- /dev/null +++ b/src/Ursa/Controls/DateTimePicker/IDateSelector.cs @@ -0,0 +1,17 @@ +namespace Ursa.Controls; + +public interface IDateSelector +{ + public bool IsValid(DateTime? date); +} + +public class WeekendDateSelector: IDateSelector +{ + public static WeekendDateSelector Instance { get; } = new WeekendDateSelector(); + + public bool IsValid(DateTime? date) + { + if (date is null) return false; + return date.Value.DayOfWeek == DayOfWeek.Saturday || date.Value.DayOfWeek == DayOfWeek.Sunday; + } +} \ No newline at end of file