예제 #1
0
def date_from_ISO8601(d_str):
    """Returns a date instance parsed from the ISO 8601 format
    (the date part of the format).
    @param d_str: A string representing a date.
    @return A datetime.date instance
    """
    return date(*time_strptime(d_str, DATE_ISO8601_FMT)[:3])
예제 #2
0
def date_from_str(d_str):
    "Returns a datetime.date from filled formats in settings, or None."
    for fmt in formats.get_format('DATE_INPUT_FORMATS'):
        try:
            return date(*time_strptime(d_str, fmt)[:3])
        except ValueError:
            continue
        except TypeError:
            break
예제 #3
0
def dt_from_str(dt_str):
    """Returns a datetime from filled formats in settings, or None.
    Doesn't handle microseconds.
    """
    dt = parse_datetime(dt_str)

    if dt:
        return make_aware_dt(dt) if is_naive(dt) else dt

    for fmt in formats.get_format('DATETIME_INPUT_FORMATS'):
        try:
            return make_aware_dt(datetime(*time_strptime(dt_str, fmt)[:6]))
        except ValueError:
            continue
        except TypeError:
            break
예제 #4
0
def timeformat(source, format):
    #
    # Convert the function source input parameter into its relevant couterpart
    excepted = "failed to convert specified source time into a time structure"
    if isinstance(source, (int, float)):
        try: object = time_localtime(source)
        except Exception as reason: raise Exception(excepted) from reason
    elif isinstance(source, str):
        try: object = time_strptime(source, format)
        except Exception as reason: raise Exception(excepted) from reason
    #
    # Determine the Unix epoch time and format the timestamp using time object
    excepted = "failed to calculate base Unix epoch time using time structure"
    try: epoch = round(time_mktime(object), 3)
    except Exception as reason: raise Exception(excepted) from reason
    excepted = "failed to construct the timestamp string using time structure"
    try: timestamp = time_strftime(format, object)
    except Exception as reason: raise Exception(excepted) from reason
    #
    # Returns Unix epoch and timestamp string for the provided input parameter
    return (epoch, timestamp)
예제 #5
0
def strptime_time(value, format="%H:%M"):
    return time(*time_strptime(value, format)[3:6])
예제 #6
0
 def strptime(value, format):
     return datetime(*time_strptime(value, format)[:6])
예제 #7
0
파일: date.py 프로젝트: wencadc/agros2d
def strptime_time(value, format='%H:%M'):
    return time(*time_strptime(value, format)[3:6])
예제 #8
0
파일: date.py 프로젝트: wencadc/agros2d
 def strptime(value, format):
     return datetime(*time_strptime(value, format)[:6])
예제 #9
0
def strToDatetime(datestr):
    try:
        return dt.strptime(datestr, "%Y%m%d%H%M%S")
    except TypeError:
        return dt(*(time_strptime(datestr, "%Y%m%d%H%M%S")[0:6]))