Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/dateutil/utils.py
7763 views
# -*- coding: utf-8 -*-1"""2This module offers general convenience and utility functions for dealing with3datetimes.45.. versionadded:: 2.7.06"""7from __future__ import unicode_literals89from datetime import datetime, time101112def today(tzinfo=None):13"""14Returns a :py:class:`datetime` representing the current day at midnight1516:param tzinfo:17The time zone to attach (also used to determine the current day).1819:return:20A :py:class:`datetime.datetime` object representing the current day21at midnight.22"""2324dt = datetime.now(tzinfo)25return datetime.combine(dt.date(), time(0, tzinfo=tzinfo))262728def default_tzinfo(dt, tzinfo):29"""30Sets the ``tzinfo`` parameter on naive datetimes only3132This is useful for example when you are provided a datetime that may have33either an implicit or explicit time zone, such as when parsing a time zone34string.3536.. doctest::3738>>> from dateutil.tz import tzoffset39>>> from dateutil.parser import parse40>>> from dateutil.utils import default_tzinfo41>>> dflt_tz = tzoffset("EST", -18000)42>>> print(default_tzinfo(parse('2014-01-01 12:30 UTC'), dflt_tz))432014-01-01 12:30:00+00:0044>>> print(default_tzinfo(parse('2014-01-01 12:30'), dflt_tz))452014-01-01 12:30:00-05:004647:param dt:48The datetime on which to replace the time zone4950:param tzinfo:51The :py:class:`datetime.tzinfo` subclass instance to assign to52``dt`` if (and only if) it is naive.5354:return:55Returns an aware :py:class:`datetime.datetime`.56"""57if dt.tzinfo is not None:58return dt59else:60return dt.replace(tzinfo=tzinfo)616263def within_delta(dt1, dt2, delta):64"""65Useful for comparing two datetimes that may have a negligible difference66to be considered equal.67"""68delta = abs(delta)69difference = dt1 - dt270return -delta <= difference <= delta717273