Converts datetime object to str if not yet an str.
163215
def dt2str(dt, flagSeconds=True):
    """"""
    if isinstance(dt, str):
        return dt
    return dt.strftime(_FMTS if flagSeconds else _FMT)
751256
def _x_format(self):
        """"""

        def date_to_str(x):
            d = datetime.utcfromtimestamp(x).date()
            return self.x_value_formatter(d)

        return date_to_str
701704
def to_datetime(date):
    """"""
    return datetime.datetime(date.year, date.month, date.day)
10028
def _encode_datetime(obj):
    """"""

    if isinstance(obj, datetime.datetime):
        obj = {'__datetime__': True, 'as_str': obj.strftime("%Y%m%dT%H:%M:%S.%f").encode()}
    return obj
706251
public static String toStringWithSeconds( DateTime dateTime ) {
        String dtStr = dateTime.toString(withSecondsformatter);
        return dtStr;
    }
1216892
def _convert_time(self, time_str):
        
        dt = datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%SZ")
        return int(time.mktime(dt.utctimetuple()))
1204504
def dtstr_to_datetime(dtstr, to_tz=None, fail_silently=True):
    
    try:
        dt = datetime.datetime.utcfromtimestamp(int(dtstr, 36) / 1e3)
        if to_tz:
            dt = timezone.make_aware(dt, timezone=pytz.UTC)
            if to_tz != pytz.UTC:
                dt = dt.astimezone(to_tz)
        return dt
    except ValueError, e:
        if not fail_silently:
            raise e
        return None
170770
def to_repr(value, ctx):
    
    as_string = to_string(value, ctx)

    if isinstance(value, str) or isinstance(value, datetime.date) or isinstance(value, datetime.time):
        as_string = as_string.replace('"', '""')  # escape quotes by doubling
        as_string = '"%s"' % as_string

    return as_string
700394
def str_to_date(date: str) -> datetime.datetime:
    
    date = date.split('.')
    date.reverse()
    y, m, d = date
    return datetime.datetime(int(y), int(m), int(d))
399668
def string_to_datetime(self, obj):
        
        if isinstance(obj, six.string_types) and len(obj) == 19:
            try:
                return datetime.strptime(obj, "%Y-%m-%dT%H:%M:%S")
            except ValueError:
                pass
        if isinstance(obj, six.string_types) and len(obj) > 19:
            try:
                return datetime.strptime(obj, "%Y-%m-%dT%H:%M:%S.%f")
            except ValueError:
                pass
        if isinstance(obj, six.string_types) and len(obj) == 10:
            try:
                return datetime.strptime(obj, "%Y-%m-%d")
            except ValueError:
                pass
        return obj
1258313
def _x_format(self):
        """"""

        def datetime_to_str(x):
            dt = datetime.utcfromtimestamp(x)
            return self.x_value_formatter(dt)

        return datetime_to_str
283023
def datetime_to_str(date_time=None, str_format='%Y-%m-%d_%H:%M:%S.fff'):
    
    date_time = date_time or cst_now()
    if DEFAULT_TIMEZONE_AWARE:
        date_time += timedelta(hours=DEFAULT_TIMEZONE)
    ret = date_time.strftime(str_format.split('.f')[0])
    if '.f' in str_format:
        sig_digits = len(str_format.split('.')[-1]) + 1
        ret += str(date_time.microsecond / 1000000.0
                   )[1:].ljust(sig_digits, '0')[:sig_digits]
    return ret
685170
def TAF_datetime_to_datetime_object(
    datetime_string             = None,
    datetime_for_year_and_month = None  # e.g. datetime.datetime.utcnow()
    ):

    

    if datetime_string.endswith("24"):

        datetime_string = datetime_string[:-2] + "00"

        tmp = datetime.datetime.strptime(datetime_string, "%d%H") +\
              datetime.timedelta(days = 1)

    else:

        tmp = datetime.datetime.strptime(datetime_string, "%d%H")

    return datetime.datetime(
        datetime_for_year_and_month.year,
        datetime_for_year_and_month.month,
        tmp.day,
        tmp.hour,
        tmp.minute
    )
745950
def _str_datetime_now(self, x=None):
        
        if (x == 'now'):
            # Now, this is wht datetime_to_str() with no arg gives
            return(datetime_to_str())
        try:
            # Test for number
            junk = x + 0.0
            return datetime_to_str(x)
        except TypeError:
            # Didn't look like a number, treat as string
            return x
609304
def to_json(self, value):
        
        if isinstance(value, datetime.datetime):
            return value.strftime(self.DATETIME_FORMAT)
        if value is None:
            return None
        raise TypeError("Value stored must be a datetime object, not {}".format(type(value)))
837593
def check_str(obj):
        
        if isinstance(obj, str):
            return obj
        if isinstance(obj, float):
            return str(int(obj))
        else:
            return str(obj)
27574
def repr_timestamp(timestamp):
    """"""
    if timestamp is None:
        return 'None'
    dt = datetime_from_timestamp(timestamp)
    ret = "%d (%s)" % (timestamp,
                       dt.strftime('%Y-%m-%d %H:%M:%S.%f %Z'))
    return ret