Python datetime.html() Examples

The following are 30 code examples for showing how to use datetime.html(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module datetime , or try the search function .

Example 1
Project: faces   Author: skarlekar   File: compat.py    License: GNU General Public License v2.0 6 votes vote down vote up
def total_seconds(delta):
    """
    Returns the total seconds in a ``datetime.timedelta``.

    Python 2.6 does not have ``timedelta.total_seconds()``, so we have
    to calculate this ourselves. On 2.7 or better, we'll take advantage of the
    built-in method.

    The math was pulled from the ``datetime`` docs
    (http://docs.python.org/2.7/library/datetime.html#datetime.timedelta.total_seconds).

    :param delta: The timedelta object
    :type delta: ``datetime.timedelta``
    """
    if sys.version_info[:2] != (2, 6):
        return delta.total_seconds()

    day_in_seconds = delta.days * 24 * 3600.0
    micro_in_seconds = delta.microseconds / 10.0**6
    return day_in_seconds + delta.seconds + micro_in_seconds


# Checks to see if md5 is available on this system. A given system might not
# have access to it for various reasons, such as FIPS mode being enabled. 
Example 2
Project: faces   Author: skarlekar   File: compat.py    License: GNU General Public License v2.0 6 votes vote down vote up
def total_seconds(delta):
    """
    Returns the total seconds in a ``datetime.timedelta``.

    Python 2.6 does not have ``timedelta.total_seconds()``, so we have
    to calculate this ourselves. On 2.7 or better, we'll take advantage of the
    built-in method.

    The math was pulled from the ``datetime`` docs
    (http://docs.python.org/2.7/library/datetime.html#datetime.timedelta.total_seconds).

    :param delta: The timedelta object
    :type delta: ``datetime.timedelta``
    """
    if sys.version_info[:2] != (2, 6):
        return delta.total_seconds()

    day_in_seconds = delta.days * 24 * 3600.0
    micro_in_seconds = delta.microseconds / 10.0**6
    return day_in_seconds + delta.seconds + micro_in_seconds


# Checks to see if md5 is available on this system. A given system might not
# have access to it for various reasons, such as FIPS mode being enabled. 
Example 3
Project: deepWordBug   Author: QData   File: compat.py    License: Apache License 2.0 6 votes vote down vote up
def total_seconds(delta):
    """
    Returns the total seconds in a ``datetime.timedelta``.

    Python 2.6 does not have ``timedelta.total_seconds()``, so we have
    to calculate this ourselves. On 2.7 or better, we'll take advantage of the
    built-in method.

    The math was pulled from the ``datetime`` docs
    (http://docs.python.org/2.7/library/datetime.html#datetime.timedelta.total_seconds).

    :param delta: The timedelta object
    :type delta: ``datetime.timedelta``
    """
    if sys.version_info[:2] != (2, 6):
        return delta.total_seconds()

    day_in_seconds = delta.days * 24 * 3600.0
    micro_in_seconds = delta.microseconds / 10.0**6
    return day_in_seconds + delta.seconds + micro_in_seconds


# Checks to see if md5 is available on this system. A given system might not
# have access to it for various reasons, such as FIPS mode being enabled. 
Example 4
Project: ara   Author: ansible-community   File: datetime_formatting.py    License: GNU General Public License v3.0 6 votes vote down vote up
def past_timestamp(weeks=0, days=0, hours=0, minutes=0, seconds=0):
    """
    Produces a timestamp from the past compatible with the API.
    Used to provide time ranges by templates.
    Expects a dictionary of arguments to timedelta, for example:
        datetime.timedelta(hours=24)
        datetime.timedelta(days=7)
    See: https://docs.python.org/3/library/datetime.html#datetime.timedelta
    """
    delta = dict()
    if weeks:
        delta["weeks"] = weeks
    if days:
        delta["days"] = days
    if hours:
        delta["hours"] = hours
    if minutes:
        delta["minutes"] = minutes
    if seconds:
        delta["seconds"] = seconds

    return (datetime.datetime.now() - datetime.timedelta(**delta)).isoformat() 
Example 5
Project: bash-lambda-layer   Author: gkrizek   File: compat.py    License: MIT License 6 votes vote down vote up
def total_seconds(delta):
    """
    Returns the total seconds in a ``datetime.timedelta``.

    Python 2.6 does not have ``timedelta.total_seconds()``, so we have
    to calculate this ourselves. On 2.7 or better, we'll take advantage of the
    built-in method.

    The math was pulled from the ``datetime`` docs
    (http://docs.python.org/2.7/library/datetime.html#datetime.timedelta.total_seconds).

    :param delta: The timedelta object
    :type delta: ``datetime.timedelta``
    """
    if sys.version_info[:2] != (2, 6):
        return delta.total_seconds()

    day_in_seconds = delta.days * 24 * 3600.0
    micro_in_seconds = delta.microseconds / 10.0**6
    return day_in_seconds + delta.seconds + micro_in_seconds


# Checks to see if md5 is available on this system. A given system might not
# have access to it for various reasons, such as FIPS mode being enabled. 
Example 6
Project: AWS-Transit-Gateway-Demo-MultiAccount   Author: MattTunny   File: compat.py    License: MIT License 6 votes vote down vote up
def total_seconds(delta):
    """
    Returns the total seconds in a ``datetime.timedelta``.

    Python 2.6 does not have ``timedelta.total_seconds()``, so we have
    to calculate this ourselves. On 2.7 or better, we'll take advantage of the
    built-in method.

    The math was pulled from the ``datetime`` docs
    (http://docs.python.org/2.7/library/datetime.html#datetime.timedelta.total_seconds).

    :param delta: The timedelta object
    :type delta: ``datetime.timedelta``
    """
    if sys.version_info[:2] != (2, 6):
        return delta.total_seconds()

    day_in_seconds = delta.days * 24 * 3600.0
    micro_in_seconds = delta.microseconds / 10.0**6
    return day_in_seconds + delta.seconds + micro_in_seconds


# Checks to see if md5 is available on this system. A given system might not
# have access to it for various reasons, such as FIPS mode being enabled. 
Example 7
Project: AWS-Transit-Gateway-Demo-MultiAccount   Author: MattTunny   File: compat.py    License: MIT License 6 votes vote down vote up
def total_seconds(delta):
    """
    Returns the total seconds in a ``datetime.timedelta``.

    Python 2.6 does not have ``timedelta.total_seconds()``, so we have
    to calculate this ourselves. On 2.7 or better, we'll take advantage of the
    built-in method.

    The math was pulled from the ``datetime`` docs
    (http://docs.python.org/2.7/library/datetime.html#datetime.timedelta.total_seconds).

    :param delta: The timedelta object
    :type delta: ``datetime.timedelta``
    """
    if sys.version_info[:2] != (2, 6):
        return delta.total_seconds()

    day_in_seconds = delta.days * 24 * 3600.0
    micro_in_seconds = delta.microseconds / 10.0**6
    return day_in_seconds + delta.seconds + micro_in_seconds


# Checks to see if md5 is available on this system. A given system might not
# have access to it for various reasons, such as FIPS mode being enabled. 
Example 8
Project: aws-extender   Author: VirtueSecurity   File: compat.py    License: MIT License 6 votes vote down vote up
def total_seconds(delta):
    """
    Returns the total seconds in a ``datetime.timedelta``.

    Python 2.6 does not have ``timedelta.total_seconds()``, so we have
    to calculate this ourselves. On 2.7 or better, we'll take advantage of the
    built-in method.

    The math was pulled from the ``datetime`` docs
    (http://docs.python.org/2.7/library/datetime.html#datetime.timedelta.total_seconds).

    :param delta: The timedelta object
    :type delta: ``datetime.timedelta``
    """
    if sys.version_info[:2] != (2, 6):
        return delta.total_seconds()

    day_in_seconds = delta.days * 24 * 3600.0
    micro_in_seconds = delta.microseconds / 10.0**6
    return day_in_seconds + delta.seconds + micro_in_seconds


# Checks to see if md5 is available on this system. A given system might not
# have access to it for various reasons, such as FIPS mode being enabled. 
Example 9
def validate(self, value):
        validation_errors = super(DateTimeField, self).validate(value)
        if value is None:
            pass
        elif not isinstance(value, datetime.datetime):
            validation_errors.append('The value is not a datetime')
        elif value.utcoffset() is None:
            validation_errors.append('The value is a naive datetime.')
        elif value.utcoffset().total_seconds() != 0:
            validation_errors.append('The value must use UTC timezone.')
        elif value.year < 1900:
            # https://docs.python.org/2/library/datetime.html?highlight=strftime#strftime-strptime-behavior
            # "The exact range of years for which strftime() works also varies across platforms. Regardless of platform, years before 1900 cannot be used."
            validation_errors.append('The value must be a date after 1900.')

        return validation_errors 
Example 10
Project: cfgrib   Author: ecmwf   File: cfmessage.py    License: Apache License 2.0 6 votes vote down vote up
def from_grib_date_time(message, date_key='dataDate', time_key='dataTime', epoch=DEFAULT_EPOCH):
    # type: (T.Mapping, str, str, datetime.datetime) -> int
    """
    Return the number of seconds since the ``epoch`` from the values of the ``message`` keys,
    using datetime.total_seconds().

    :param message: the target GRIB message
    :param date_key: the date key, defaults to "dataDate"
    :param time_key: the time key, defaults to "dataTime"
    :param epoch: the reference datetime
    """
    date = message[date_key]
    time = message[time_key]
    hour = time // 100
    minute = time % 100
    year = date // 10000
    month = date // 100 % 100
    day = date % 100
    data_datetime = datetime.datetime(year, month, day, hour, minute)
    # Python 2 compatible timestamp implementation without timezone hurdle
    # see: https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp
    return int((data_datetime - epoch).total_seconds()) 
Example 11
Project: suds   Author: suds-community   File: date.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def tzname(self, dt):
        """
        http://docs.python.org/library/datetime.html#datetime.tzinfo.tzname

        """
        # total_seconds was introduced in Python 2.7
        if hasattr(self.__offset, "total_seconds"):
            total_seconds = self.__offset.total_seconds()
        else:
            total_seconds = (self.__offset.days * 24 * 60 * 60) + \
                            (self.__offset.seconds)

        hours = total_seconds // (60 * 60)
        total_seconds -= hours * 60 * 60

        minutes = total_seconds // 60
        total_seconds -= minutes * 60

        seconds = total_seconds // 1
        total_seconds -= seconds

        if seconds:
            return "%+03d:%02d:%02d" % (hours, minutes, seconds)
        return "%+03d:%02d" % (hours, minutes) 
Example 12
Project: aws-builders-fair-projects   Author: aws-samples   File: compat.py    License: Apache License 2.0 6 votes vote down vote up
def total_seconds(delta):
    """
    Returns the total seconds in a ``datetime.timedelta``.

    Python 2.6 does not have ``timedelta.total_seconds()``, so we have
    to calculate this ourselves. On 2.7 or better, we'll take advantage of the
    built-in method.

    The math was pulled from the ``datetime`` docs
    (http://docs.python.org/2.7/library/datetime.html#datetime.timedelta.total_seconds).

    :param delta: The timedelta object
    :type delta: ``datetime.timedelta``
    """
    if sys.version_info[:2] != (2, 6):
        return delta.total_seconds()

    day_in_seconds = delta.days * 24 * 3600.0
    micro_in_seconds = delta.microseconds / 10.0**6
    return day_in_seconds + delta.seconds + micro_in_seconds


# Checks to see if md5 is available on this system. A given system might not
# have access to it for various reasons, such as FIPS mode being enabled. 
Example 13
Project: Python24   Author: HaoZhang95   File: writer.py    License: MIT License 5 votes vote down vote up
def _format_list(v):
    return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))

# Formula from:
#   https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
# Once support for py26 is dropped, this can be replaced by td.total_seconds() 
Example 14
Project: FuYiSpider   Author: wangzhenjjcn   File: writer.py    License: Apache License 2.0 5 votes vote down vote up
def _format_list(v):
    return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))

# Formula from:
#   https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
# Once support for py26 is dropped, this can be replaced by td.total_seconds() 
Example 15
Project: FuYiSpider   Author: wangzhenjjcn   File: writer.py    License: Apache License 2.0 5 votes vote down vote up
def _format_list(v):
    return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))

# Formula from:
#   https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
# Once support for py26 is dropped, this can be replaced by td.total_seconds() 
Example 16
Project: PandasSchema   Author: TMiguelT   File: validation.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, pattern, options={}, **kwargs):
        """
        :param kwargs: Arguments to pass to Series.str.contains
            (http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.contains.html)
            pat is the only required argument
        """
        self.pattern = pattern
        self.options = options
        super().__init__(**kwargs) 
Example 17
Project: PandasSchema   Author: TMiguelT   File: validation.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, date_format: str, **kwargs):
        """
        :param date_format: The date format string to validate the column against. Refer to the date format code
            documentation at https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior for a full
            list of format codes
        """
        self.date_format = date_format
        super().__init__(**kwargs) 
Example 18
Project: GraphicDesignPatternByPython   Author: Relph1119   File: writer.py    License: MIT License 5 votes vote down vote up
def _format_list(v):
    return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))

# Formula from:
#   https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
# Once support for py26 is dropped, this can be replaced by td.total_seconds() 
Example 19
Project: hacktoberfest2018   Author: ambujraj   File: writer.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _format_list(v):
    return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))

# Formula from:
#   https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
# Once support for py26 is dropped, this can be replaced by td.total_seconds() 
Example 20
Project: hacktoberfest2018   Author: ambujraj   File: writer.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _format_list(v):
    return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))

# Formula from:
#   https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
# Once support for py26 is dropped, this can be replaced by td.total_seconds() 
Example 21
Project: nokia-weight-sync   Author: magnific0   File: nokia.py    License: GNU General Public License v3.0 5 votes vote down vote up
def is_date_class(val):
    return isinstance(val, (datetime.date, datetime.datetime, arrow.Arrow, ))


# Calculate seconds since 1970-01-01 (timestamp) in a way that works in
# Python 2 and Python3
# https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp 
Example 22
Project: pySINDy   Author: luckystarufo   File: writer.py    License: MIT License 5 votes vote down vote up
def _format_list(v):
    return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))

# Formula from:
#   https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
# Once support for py26 is dropped, this can be replaced by td.total_seconds() 
Example 23
Project: stopstalk-deployment   Author: stopstalk   File: writer.py    License: MIT License 5 votes vote down vote up
def _format_list(v):
    return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))

# Formula from:
#   https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
# Once support for py26 is dropped, this can be replaced by td.total_seconds() 
Example 24
Project: insights-core   Author: RedHatInsights   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def parse_bool(s, default=False):
    """
    Return the boolean value of an English string or default if it can't be
    determined.
    """
    if s is None:
        return default
    return TRUTH.get(s.lower(), default)


# python2 doesn't have a utc tzinfo by default
# see https://docs.python.org/2/library/datetime.html#tzinfo-objects 
Example 25
Project: suds-py3   Author: cackharot   File: date.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def utcoffset(self, dt):
        """
        http://docs.python.org/library/datetime.html#datetime.tzinfo.utcoffset

        """
        return self.__offset 
Example 26
Project: suds-py3   Author: cackharot   File: date.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def tzname(self, dt):
        """
        http://docs.python.org/library/datetime.html#datetime.tzinfo.tzname

        """
        sign = '+'
        if self.__offset < datetime.timedelta():
            sign = '-'

        # total_seconds was introduced in Python 2.7
        if hasattr(self.__offset, 'total_seconds'):
            total_seconds = self.__offset.total_seconds()
        else:
            total_seconds = (self.__offset.days * 24 * 60 * 60) + \
                            (self.__offset.seconds) + \
                            (self.__offset.microseconds / 1000000.0)

        hours = total_seconds // (60 * 60)
        total_seconds -= hours * 60 * 60

        minutes = total_seconds // 60
        total_seconds -= minutes * 60

        seconds = total_seconds // 1
        total_seconds -= seconds

        if seconds:
            return '%s%02d:%02d:%02d' % (sign, hours, minutes, seconds)
        else:
            return '%s%02d:%02d' % (sign, hours, minutes) 
Example 27
Project: suds-py3   Author: cackharot   File: date.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def dst(self, dt):
        """
        http://docs.python.org/library/datetime.html#datetime.tzinfo.dst

        """
        return datetime.timedelta(0) 
Example 28
Project: suds-py3   Author: cackharot   File: date.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def tzname(self, dt):
        """
        http://docs.python.org/library/datetime.html#datetime.tzinfo.tzname

        """
        return 'UTC' 
Example 29
Project: suds-py3   Author: cackharot   File: date.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def utcoffset(self, dt):
        """
        http://docs.python.org/library/datetime.html#datetime.tzinfo.utcoffset

        """
        if self.__is_daylight_time(dt):
            return self.__dst_offset
        else:
            return self.__offset 
Example 30
Project: suds-py3   Author: cackharot   File: date.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def tzname(self, dt):
        """
        http://docs.python.org/library/datetime.html#datetime.tzinfo.tzname

        """
        if self.__is_daylight_time(dt):
            return time.tzname[1]
        else:
            return time.tzname[0]