utils

This module offers general convenience and utility functions for dealing with datetimes.

New in version 2.7.0.

Module Contents

Functions

today(tzinfo=None) Returns a datetime representing the current day at midnight
default_tzinfo(dt,tzinfo) Sets the the tzinfo parameter on naive datetimes only
within_delta(dt1,dt2,delta) Useful for comparing two datetimes that may a negilible difference
today(tzinfo=None)

Returns a datetime representing the current day at midnight

Parameters:tzinfo – The time zone to attach (also used to determine the current day).
Returns:A datetime.datetime object representing the current day at midnight.
default_tzinfo(dt, tzinfo)

Sets the the tzinfo parameter on naive datetimes only

This is useful for example when you are provided a datetime that may have either an implicit or explicit time zone, such as when parsing a time zone string.

Parameters:
  • dt – The datetime on which to replace the time zone
  • tzinfo – The datetime.tzinfo subclass instance to assign to dt if (and only if) it is naive.
Returns:

Returns an aware datetime.datetime.

within_delta(dt1, dt2, delta)

Useful for comparing two datetimes that may a negilible difference to be considered equal.