# Path: minette/utils.py
# def date_to_str(dt, with_timezone=False):
#     """
#     Convert datetime to str
# 
#     Parameters
#     ----------
#     dt : datetime
#         datetime to convert
#     with_timezone : bool, default False
#         Include timezone or not
# 
#     Returns
#     -------
#     datetime_str : str
#         Datetime string
#     """
#     if with_timezone and dt.tzinfo:
#         dtstr = dt.strftime("%Y-%m-%dT%H:%M:%S.%f%z")
#         return dtstr[:-2] + ":" + dtstr[-2:]
#     else:
#         return dt.strftime("%Y-%m-%dT%H:%M:%S.%f")
# 
# def str_to_date(dtstr):
#     """
#     Convert str to datetime
# 
#     Parameters
#     ----------
#     dtstr : str
#         str to convert
# 
#     Returns
#     -------
#     datetime : datetime
#         datetime
#     """
#     if len(dtstr) > 19 and dtstr[-3:-2] == ":":
#         dtstr = dtstr[:-3] + dtstr[-2:]
#     fmt = "%Y-%m-%dT%H:%M:%S"
#     if "." in dtstr:
#         fmt += ".%f"
#     if dtstr[-5] == "+" or dtstr[-5] == "-":
#         fmt += "%z"
#     return datetime.strptime(dtstr, fmt)


import json
import re
from datetime import datetime
from .utils import date_to_str, str_to_date


def _is_datestring(s):
    return isinstance(s, str) and \
        re.match(r"(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})", s)


def _encode_datetime(obj):
    if isinstance(obj, datetime):
        return date_to_str(obj, obj.tzinfo is not None)


def _decode_datetime(d):
    for k in d:
        if _is_datestring(d[k]):
            d[k] = str_to_date(d[k])
        if isinstance(d[k], list):
            for i, v in enumerate(d[k]):
                if _is_datestring(v):

# Path: minette/utils.py
# def date_to_str(dt, with_timezone=False):
#     """
#     Convert datetime to str
# 
#     Parameters
#     ----------
#     dt : datetime
#         datetime to convert
#     with_timezone : bool, default False
#         Include timezone or not
# 
#     Returns
#     -------
#     datetime_str : str
#         Datetime string
#     """
#     if with_timezone and dt.tzinfo:
#         dtstr = dt.strftime("%Y-%m-%dT%H:%M:%S.%f%z")
#         return dtstr[:-2] + ":" + dtstr[-2:]
#     else:
#         return dt.strftime("%Y-%m-%dT%H:%M:%S.%f")
# 
# def str_to_date(dtstr):
#     """
#     Convert str to datetime
# 
#     Parameters
#     ----------
#     dtstr : str
#         str to convert
# 
#     Returns
#     -------
#     datetime : datetime
#         datetime
#     """
#     if len(dtstr) > 19 and dtstr[-3:-2] == ":":
#         dtstr = dtstr[:-3] + dtstr[-2:]
#     fmt = "%Y-%m-%dT%H:%M:%S"
#     if "." in dtstr:
#         fmt += ".%f"
#     if dtstr[-5] == "+" or dtstr[-5] == "-":
#         fmt += "%z"
#     return datetime.strptime(dtstr, fmt)


# Path: minette/serializer.py
import json
import re
from datetime import datetime
from .utils import date_to_str, str_to_date



def _is_datestring(s):
    return isinstance(s, str) and \
        re.match(r"(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})", s)


def _encode_datetime(obj):
    if isinstance(obj, datetime):
        return date_to_str(obj, obj.tzinfo is not None)


def _decode_datetime(d):
    for k in d:
        if _is_datestring(d[k]):
            d[k] = str_to_date(d[k])
        if isinstance(d[k], list):
            for i, v in enumerate(d[k]):
                if _is_datestring(v):

                    d[k][i] = str_to_date(v)