Merge pull request #27429 from Vishnu7025/utils-functions

feat: add get_month function to return current or specific month as a…
This commit is contained in:
Sumit Bhanushali 2024-08-22 01:18:44 +05:30 committed by GitHub
commit 60fe377a72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View file

@ -2,6 +2,7 @@
# License: MIT. See LICENSE
import base64
import calendar
import datetime
import hashlib
import json
@ -878,6 +879,20 @@ def get_weekday(datetime: DateTimeLikeObject | None = None) -> str:
return weekdays[datetime.weekday()]
def get_month(datetime: DateTimeLikeObject | None = None) -> str:
"""Return the month name (e.g. 'January') for the given datetime like object (datetime.date, datetime.datetime, string).
If `datetime` argument is not provided, the current month name is returned.
"""
if not datetime:
datetime = now_datetime()
if isinstance(datetime, str):
datetime = get_datetime(datetime)
return calendar.month_name[datetime.month]
def get_timespan_date_range(
timespan: TimespanOptions,
) -> tuple[datetime.datetime, datetime.datetime] | None:

View file

@ -656,6 +656,7 @@ VALID_UTILS = (
"formatdate",
"get_user_info_for_avatar",
"get_abbr",
"get_month",
)