# Path: timestream/util/validation.py
# def v_datetime(x, format="%Y_%m_%d_%H_%M_%S"):
#     """Validate string contains a date in ``fmt`` strptime-compatible format,
#     and coerce to a ``datetime.datetime`` object.
# 
#     :arg str x: String to validate.
#     :keyword str fmt: String date format to strip time with.
#     :returns:  the parsed object
#     :rtype: datetime.datetime
#     :raises: ``ValueError``
#     """
#     if isinstance(x, datetime.datetime):
#         return x
#     else:
#         return datetime.datetime.strptime(x, format)
# 
# def v_num_str(x):
#     """Validate an object that can be coerced to an ``int``."""
#     return int(x)


from os import path
from voluptuous import Schema, Required, Range, All, Length, Any
from timestream.util.validation import (
    v_datetime,
    v_num_str,
)
    '%Y_%m_%d_%H',
    '{tsname:s}_%Y_%m_%d_%H_%M_%S_{n:02d}.{ext:s}',
]
TS_V1_FMT = path.join(*__TS_V1_LEVELS)

TS_MANIFEST_KEYS = [
    "name",
    "version",
    "start_datetime",
    "end_datetime",
    "image_type",
    "extension",
    "interval",
]


def validate_timestream_manifest(manifest):
    """Validtes a json manifest, and returns the validated ``dict``

    :param dict manifest: The raw json manifest from ``json.load`` or similar.
    :returns: The validated and type-converted manifest as a ``dict``
    :rtype: dict
    :raises: TypeError, MultipleInvalid
    """
    if not isinstance(manifest, dict):
        raise TypeError("Manfiest should be in ``dict`` form.")
    sch = Schema({
        Required("name"): All(str, Length(min=1)),
        Required("version"): All(v_num_str, Range(min=1, max=2)),
        Required("start_datetime"): v_datetime,

# Path: timestream/util/validation.py
# def v_datetime(x, format="%Y_%m_%d_%H_%M_%S"):
#     """Validate string contains a date in ``fmt`` strptime-compatible format,
#     and coerce to a ``datetime.datetime`` object.
# 
#     :arg str x: String to validate.
#     :keyword str fmt: String date format to strip time with.
#     :returns:  the parsed object
#     :rtype: datetime.datetime
#     :raises: ``ValueError``
#     """
#     if isinstance(x, datetime.datetime):
#         return x
#     else:
#         return datetime.datetime.strptime(x, format)
# 
# def v_num_str(x):
#     """Validate an object that can be coerced to an ``int``."""
#     return int(x)


# Path: timestream/parse/validate.py
from os import path
from voluptuous import Schema, Required, Range, All, Length, Any
from timestream.util.validation import (
    v_datetime,
    v_num_str,
)

    '%Y_%m_%d_%H',
    '{tsname:s}_%Y_%m_%d_%H_%M_%S_{n:02d}.{ext:s}',
]
TS_V1_FMT = path.join(*__TS_V1_LEVELS)

TS_MANIFEST_KEYS = [
    "name",
    "version",
    "start_datetime",
    "end_datetime",
    "image_type",
    "extension",
    "interval",
]


def validate_timestream_manifest(manifest):
    """Validtes a json manifest, and returns the validated ``dict``

    :param dict manifest: The raw json manifest from ``json.load`` or similar.
    :returns: The validated and type-converted manifest as a ``dict``
    :rtype: dict
    :raises: TypeError, MultipleInvalid
    """
    if not isinstance(manifest, dict):
        raise TypeError("Manfiest should be in ``dict`` form.")
    sch = Schema({
        Required("name"): All(str, Length(min=1)),
        Required("version"): All(v_num_str, Range(min=1, max=2)),
        Required("start_datetime"): v_datetime,

        Required("end_datetime"): v_datetime,