devilry.utils.datetimeutils
¶
- devilry.utils.datetimeutils.ISODATETIME_DJANGOFORMAT = 'Y-m-d H:i'¶
Django datetime formatting string for
YYYY-MM-DD hh:mm
.
- devilry.utils.datetimeutils.get_current_datetime()¶
Get the current datetime as a
datetime.datetime
object.We use this because it is easier to mock in unit tests than a built-in or third party implementation.
- devilry.utils.datetimeutils.default_timezone_datetime(*args, **kwargs)¶
Create a timezone-aware
datetime.datetime
object.The parameters are the same as for
datetime.datetime
.
- devilry.utils.datetimeutils.isoformat_noseconds(datetimeobject)¶
Format the given
datetime.datetime
object asYYYY-MM-DD hh:mm
.
- devilry.utils.datetimeutils.isoformat_withseconds(datetimeobject)¶
Format the given
datetime.datetime
object asYYYY-MM-DD hh:mm
.
- devilry.utils.datetimeutils.datetime_with_same_day_of_week_and_time(weekdayandtimesource_datetime, target_datetime)¶
Returns a new datetime object with the same time and day of week as the given
target_datetime
, with the day of week moved forward to match theweekdayandtimesource_datetime
, and the time matching theweekdayandtimesource_datetime
.This means that if you send in a
weekdayandtimesource_datetime
with tuesday as the weekday, the return value will be a datetime object with the day set to the next tuesday unless the current day is monday or tuesday.
- devilry.utils.datetimeutils.datetime_to_url_string(datetime_obj)¶
Converts datetime object to URL-friendly string.
- Parameters:
datetime_obj (
django.utils.timezone
) –datetime
obj to convert.- Returns:
Datetime as string specified by
URL_DATETIME_FORMAT
.- Return type:
(str)
- devilry.utils.datetimeutils.datetime_url_string_to_datetime(datetime_string)¶
Convert URL-friendly string to
django.utils.timezone
datetime object. :param datetime_string: String to convert. :type datetime_string: str- Returns:
Converted datetime object from string.
- Return type:
(
django.utils.timezone
)