aiogram_calendar icon indicating copy to clipboard operation
aiogram_calendar copied to clipboard

[enchantment] Range of available dates

Open o-murphy opened this issue 1 year ago • 5 comments

Previously I uses a fork of your library to append a dates choices range to it E.g. it was to get user to chose dates for a restaurant table booking You have to add this features to your library:

  • [x] ~~Init calendar instance with optional min and max available date~~
  • [x] ~~Hightlight the "tooday" day in calendar view with ("[20]" or "*20*" symbols)~~
  • [ ] Show the callback popup reply if user tries to switch the month, year etc to date out of range
  • [x] ~~Show the callback popup reply if user tries to select the date out of range~~
  • [x] ~~Implement the way to highlight the available range of dates, for example, do not display button's text for dates that out of range~~
  • [ ] Add the Time selection calendar that looks like on the video bellow, it might accept a list of available times

https://github.com/noXplode/aiogram_calendar/assets/73843436/66986c23-c6d4-4033-8741-d3f8fea953c0

o-murphy avatar Nov 29 '23 12:11 o-murphy

I can also add a range of dates support if you want

I can add a min max properties and also add a behavior modes like Alert/NoAlert/HideUnavailable

o-murphy avatar Nov 29 '23 13:11 o-murphy

  • I think we can format the text for days that out of range as subscript/superscript using Unicode
  • We also have to add a method to override the dates range for already existing calendar (cause the range can move with the current time change)

o-murphy avatar Nov 29 '23 20:11 o-murphy

UPD #16

  • fix now month highlight
  • added min_date, max_date optional parameters
  • added superscript formatting for out of range
  • added GenericCalendar.set_dates_range method
  • added property GenericCalendar.show_alerts (defines how the date range error would shown)
  • added processing the selection date that out of range

Usage

# default way of displaying a selector to user - date set for today
@dp.message(F.text.lower() == 'navigation calendar')
async def nav_cal_handler(message: Message):
    calendar = SimpleCalendar(locale=await get_user_locale(message.from_user), show_alerts=True)
    calendar.set_dates_range(datetime.datetime(2023, 11, 5), datetime.datetime(2023, 11, 25))
    await message.answer(
        "Please select a date: ",
        reply_markup=await calendar.start_calendar()
    )

# simple calendar usage - filtering callbacks of calendar format
@dp.callback_query(SimpleCalendarCallback.filter())
async def process_simple_calendar(callback_query: CallbackQuery, callback_data: CallbackData):
    calendar = SimpleCalendar(
        locale=await get_user_locale(callback_query.from_user), show_alerts=True
    )
    calendar.set_dates_range(datetime.datetime(2023, 11, 5), datetime.datetime(2023, 11, 25))
    selected, date = await calendar.process_selection(callback_query, callback_data)
    if selected:
        await callback_query.message.answer(
            f'You selected {date.strftime("%d/%m/%Y")}',
            reply_markup=start_kb
        )

image image image

o-murphy avatar Nov 29 '23 22:11 o-murphy

ok, checked it out , will take a deeper look in a couple of days, thank you! have less free time this week

noXplode avatar Nov 30 '23 23:11 noXplode