nntp/date.py
def timestamp(value, fmt=None):
    """Parse a datetime to a unix timestamp.

    Uses fast custom parsing for common datetime formats or the slow dateutil
    parser for other formats. This is a trade off between ease of use and speed
    and is very useful for fast parsing of timestamp strings whose format may
    standard but varied or unknown prior to parsing.

    Common formats include:
        1 Feb 2010 12:00:00 GMT
        Mon, 1 Feb 2010 22:00:00 +1000
        20100201120000
        1383470155 (seconds since epoch)

    See the other timestamp_*() functions for more details.

    Args:
        value: A string representing a datetime.
        fmt: A timestamp format string like for time.strptime().

    Returns:
        The time in seconds since epoch as and integer for the value specified.
    """
    if fmt:
        return _timestamp_formats.get(fmt,
            lambda v: timestamp_fmt(v, fmt)
        )(value)

    l = len(value)

    if 19 <= l <= 24 and value[3] == " ":
        # '%d %b %Y %H:%M:%Sxxxx'
        try:
            return timestamp_d_b_Y_H_M_S(value)
        except (KeyError, ValueError, OverflowError):
            pass

    if 30 <= l <= 31:
        # '%a, %d %b %Y %H:%M:%S %z'
        try:
            return timestamp_a__d_b_Y_H_M_S_z(value)
        except (KeyError, ValueError, OverflowError):
            pass

    if l == 14:
        # '%Y%m%d%H%M%S'
        try:
            return timestamp_YmdHMS(value)
        except (ValueError, OverflowError):
            pass

    # epoch timestamp
    try:
        return timestamp_epoch(value)
    except ValueError:
        pass

    # slow version
    return timestamp_any(value)
def timestamp(value, fmt=None):
    if fmt:
        return _timestamp_formats.get(fmt,
            lambda v: timestamp_fmt(v, fmt)
        )(value)

    l = len(value)

    if 19 <= l <= 24 and value[3] == " ":
        # '%d %b %Y %H:%M:%Sxxxx'
        try:
            return timestamp_d_b_Y_H_M_S(value)
        except (KeyError, ValueError, OverflowError):
            pass

    if 30 <= l <= 31:
        # '%a, %d %b %Y %H:%M:%S %z'
        try:
            return timestamp_a__d_b_Y_H_M_S_z(value)
        except (KeyError, ValueError, OverflowError):
            pass

    if l == 14:
        # '%Y%m%d%H%M%S'
        try:
            return timestamp_YmdHMS(value)
        except (ValueError, OverflowError):
            pass

    # epoch timestamp
    try:
        return timestamp_epoch(value)
    except ValueError:
        pass

    # slow version
    return timestamp_any(value)
def timestamp ( value , fmt = None ) : if fmt : return _timestamp_formats . get ( fmt , lambda v : timestamp_fmt ( v , fmt ) ) ( value ) l = len ( value ) if 19 <= l <= 24 and value [ 3 ] == " " : # '%d %b %Y %H:%M:%Sxxxx' try : return timestamp_d_b_Y_H_M_S ( value ) except ( KeyError , ValueError , OverflowError ) : pass if 30 <= l <= 31 : # '%a, %d %b %Y %H:%M:%S %z' try : return timestamp_a__d_b_Y_H_M_S_z ( value ) except ( KeyError , ValueError , OverflowError ) : pass if l == 14 : # '%Y%m%d%H%M%S' try : return timestamp_YmdHMS ( value ) except ( ValueError , OverflowError ) : pass # epoch timestamp try : return timestamp_epoch ( value ) except ValueError : pass # slow version return timestamp_any ( value )
Parse a datetime to a unix timestamp.

    Uses fast custom parsing for common datetime formats or the slow dateutil
    parser for other formats. This is a trade off between ease of use and speed
    and is very useful for fast parsing of timestamp strings whose format may
    standard but varied or unknown prior to parsing.

    Common formats include:
        1 Feb 2010 12:00:00 GMT
        Mon, 1 Feb 2010 22:00:00 +1000
        20100201120000
        1383470155 (seconds since epoch)

    See the other timestamp_*() functions for more details.

    Args:
        value: A string representing a datetime.
        fmt: A timestamp format string like for time.strptime().

    Returns:
        The time in seconds since epoch as and integer for the value specified.
Parse a datetime to a unix timestamp .