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:
commit
60fe377a72
2 changed files with 16 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -656,6 +656,7 @@ VALID_UTILS = (
|
|||
"formatdate",
|
||||
"get_user_info_for_avatar",
|
||||
"get_abbr",
|
||||
"get_month",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue