oauth2_client/utils/date_time.py
def datetime_to_float(dt):
    """
    Convert a datetime object to a floating point timestamp.
    Return a number of seconds elapsed from the UTC epoch.

    If the input object is timezone-aware, the result includes timezone
    difference between UTC and the timezone.

    If the input object is timezone-naive, it's treated as UTC.
    NOTE: This behaviour is different from the standard's library
    `datetime.timestamp()`, that assumes local timezone.

    For example, 2h into the epoch in CET is 1h into the epoch in UTC
    (CET = UTC + 1h), so:

        >> cet_tz = timezone('CET')
        >> dt = datetime(1970, 1, 1, 2, 0, 0, tzinfo=cet_tz)
        >> datetime_to_float(dt)
        3600.0

    In case of a timezone-naive object, we treat the input as UTC, so:

        >> dt = datetime(1970, 1, 1, 2, 0)
        >> ts_expected = 3600 * 2
        >> datetime_to_float(dt)
        7200.0

    See tests for more examples.

    Args:
        dt (datetime): timezone-aware or not

    Returns:
        float: e.g. 123456.123, always counting from UTC
    """
    epoch = datetime.fromtimestamp(0, tz=pytz.UTC)
    if not dt.tzinfo:
        epoch = epoch.replace(tzinfo=None)

    total_seconds = (dt - epoch).total_seconds()
    return total_seconds

    Convert a datetime object to a floating point timestamp.
    Return a number of seconds elapsed from the UTC epoch.

    If the input object is timezone-aware, the result includes timezone
    difference between UTC and the timezone.

    If the input object is timezone-naive, it's treated as UTC.
    NOTE: This behaviour is different from the standard's library
    `datetime.timestamp()`, that assumes local timezone.

    For example, 2h into the epoch in CET is 1h into the epoch in UTC
    (CET = UTC + 1h), so:

        >> cet_tz = timezone('CET')
        >> dt = datetime(1970, 1, 1, 2, 0, 0, tzinfo=cet_tz)
        >> datetime_to_float(dt)
        3600.0

    In case of a timezone-naive object, we treat the input as UTC, so:

        >> dt = datetime(1970, 1, 1, 2, 0)
        >> ts_expected = 3600 * 2
        >> datetime_to_float(dt)
        7200.0

    See tests for more examples.

    Args:
        dt (datetime): timezone-aware or not

    Returns:
        float: e.g. 123456.123, always counting from UTC
    
Convert a datetime object to a floating point timestamp.
Return a number of seconds elapsed from the UTC epoch.

If the input object is timezone-aware, the result includes timezone
difference between UTC and the timezone.

If the input object is timezone-naive, it's treated as UTC.
NOTE: This behaviour is different from the standard's library
`datetime.timestamp()`, that assumes local timezone.

For example, 2h into the epoch in CET is 1h into the epoch in UTC
(CET = UTC + 1h), so.



In case of a timezone-naive object, we treat the input as UTC, so.



See tests for more examples.
Convert a datetime object to a floating point timestamp . Return a number of seconds elapsed from the UTC epoch . If the input object is timezone - aware the result includes timezone difference between UTC and the timezone . If the input object is timezone - naive it ' s treated as UTC . NOTE : This behaviour is different from the standard ' s library ` datetime . timestamp () ` that assumes local timezone . For example 2h into the epoch in CET is 1h into the epoch in UTC ( CET = UTC + 1h ) so . In case of a timezone - naive object we treat the input as UTC so . See tests for more examples .
def datetime_to_float(dt):
    epoch = datetime.fromtimestamp(0, tz=pytz.UTC)
    if not dt.tzinfo:
        epoch = epoch.replace(tzinfo=None)
    total_seconds = (dt - epoch).total_seconds()
    return total_seconds
def datetime_to_float ( dt ) : epoch = datetime . fromtimestamp ( 0 , tz = pytz . UTC ) if not dt . tzinfo : epoch = epoch . replace ( tzinfo = None ) total_seconds = ( dt - epoch ) . total_seconds ( ) return total_seconds
Convert a datetime object to a floating point timestamp.
Convert a datetime object to a floating point timestamp .
"""
    Convert a datetime object to a floating point timestamp.
    Return a number of seconds elapsed from the UTC epoch.

    If the input object is timezone-aware, the result includes timezone
    difference between UTC and the timezone.

    If the input object is timezone-naive, it's treated as UTC.
    NOTE: This behaviour is different from the standard's library
    `datetime.timestamp()`, that assumes local timezone.

    For example, 2h into the epoch in CET is 1h into the epoch in UTC
    (CET = UTC + 1h), so:

        >> cet_tz = timezone('CET')
        >> dt = datetime(1970, 1, 1, 2, 0, 0, tzinfo=cet_tz)
        >> datetime_to_float(dt)
        3600.0

    In case of a timezone-naive object, we treat the input as UTC, so:

        >> dt = datetime(1970, 1, 1, 2, 0)
        >> ts_expected = 3600 * 2
        >> datetime_to_float(dt)
        7200.0

    See tests for more examples.

    Args:
        dt (datetime): timezone-aware or not

    Returns:
        float: e.g. 123456.123, always counting from UTC
    """
e.g. 123456.123, always counting from UTC
e . g . 123456 . 123 always counting from UTC
float
dt
timezone-aware or not
timezone - aware or not