CalendarPicker:
+ Added days, monthes and years range check + Added language selection * Fixed default language (it is English now)
This commit is contained in:
parent
bd908db867
commit
36fb40b6bd
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Enums;
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
using TelegramBotBase.Tools;
|
||||||
using static TelegramBotBase.Tools.Arrays;
|
using static TelegramBotBase.Tools.Arrays;
|
||||||
using static TelegramBotBase.Tools.Time;
|
using static TelegramBotBase.Tools.Time;
|
||||||
|
|
||||||
@ -37,15 +37,17 @@ namespace TelegramBotBase.Controls.Inline
|
|||||||
|
|
||||||
public bool EnableYearView { get; set; } = true;
|
public bool EnableYearView { get; set; } = true;
|
||||||
|
|
||||||
public CalendarPicker()
|
public CalendarPicker(CultureInfo culture)
|
||||||
{
|
{
|
||||||
this.SelectedDate = DateTime.Today;
|
this.SelectedDate = DateTime.Today;
|
||||||
this.VisibleMonth = DateTime.Today;
|
this.VisibleMonth = DateTime.Today;
|
||||||
this.FirstDayOfWeek = DayOfWeek.Monday;
|
this.FirstDayOfWeek = DayOfWeek.Monday;
|
||||||
this.Culture = new CultureInfo("de-de");
|
this.Culture = culture;
|
||||||
this.PickerMode = eMonthPickerMode.day;
|
this.PickerMode = eMonthPickerMode.day;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CalendarPicker() : this(new CultureInfo("en-en")) { }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -124,13 +126,13 @@ namespace TelegramBotBase.Controls.Inline
|
|||||||
default:
|
default:
|
||||||
|
|
||||||
int day = 0;
|
int day = 0;
|
||||||
if (result.RawData.StartsWith("d-") && int.TryParse(result.RawData.Split('-')[1], out day))
|
if (result.RawData.StartsWith("d-") && TryParseDay(result.RawData.Split('-')[1], this.SelectedDate, out day))
|
||||||
{
|
{
|
||||||
this.SelectedDate = new DateTime(this.VisibleMonth.Year, this.VisibleMonth.Month, day);
|
this.SelectedDate = new DateTime(this.VisibleMonth.Year, this.VisibleMonth.Month, day);
|
||||||
}
|
}
|
||||||
|
|
||||||
int month = 0;
|
int month = 0;
|
||||||
if (result.RawData.StartsWith("m-") && int.TryParse(result.RawData.Split('-')[1], out month))
|
if (result.RawData.StartsWith("m-") && TryParseMonth(result.RawData.Split('-')[1], out month))
|
||||||
{
|
{
|
||||||
this.SelectedDate = new DateTime(this.VisibleMonth.Year, month, 1);
|
this.SelectedDate = new DateTime(this.VisibleMonth.Year, month, 1);
|
||||||
this.VisibleMonth = this.SelectedDate;
|
this.VisibleMonth = this.SelectedDate;
|
||||||
@ -142,7 +144,7 @@ namespace TelegramBotBase.Controls.Inline
|
|||||||
}
|
}
|
||||||
|
|
||||||
int year = 0;
|
int year = 0;
|
||||||
if (result.RawData.StartsWith("y-") && int.TryParse(result.RawData.Split('-')[1], out year))
|
if (result.RawData.StartsWith("y-") && TryParseYear(result.RawData.Split('-')[1], out year))
|
||||||
{
|
{
|
||||||
this.SelectedDate = new DateTime(year, SelectedDate.Month, SelectedDate.Day);
|
this.SelectedDate = new DateTime(year, SelectedDate.Month, SelectedDate.Day);
|
||||||
this.VisibleMonth = this.SelectedDate;
|
this.VisibleMonth = this.SelectedDate;
|
||||||
|
|||||||
@ -8,6 +8,21 @@ namespace TelegramBotBase.Tools
|
|||||||
{
|
{
|
||||||
public static class Time
|
public static class Time
|
||||||
{
|
{
|
||||||
|
public static bool TryParseDay(string src, DateTime currentDate, out int resultDay)
|
||||||
|
{
|
||||||
|
return int.TryParse(src, out resultDay) && resultDay >= 1 && resultDay <= DateTime.DaysInMonth(currentDate.Year, currentDate.Month);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryParseMonth(string src, out int resultMonth)
|
||||||
|
{
|
||||||
|
return int.TryParse(src, out resultMonth) && resultMonth >= 1 && resultMonth <= 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryParseYear(string src, out int resultYear)
|
||||||
|
{
|
||||||
|
return int.TryParse(src, out resultYear) && resultYear >= 0 && resultYear <= DateTime.MaxValue.Year;
|
||||||
|
}
|
||||||
|
|
||||||
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
|
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
|
||||||
{
|
{
|
||||||
int diff = dt.DayOfWeek - startOfWeek;
|
int diff = dt.DayOfWeek - startOfWeek;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user