(val)
Takes a date or datetime object and converts it to a format ES can read
    (see DATE_FORMATS_ARR). Strings are returned unmodified.
Takes a date or datetime object and converts it to a format ES can read
    (see DATE_FORMATS_ARR). Strings are returned unmodified.
Takes a date or datetime object and converts it to a format ES can read ( see DATE_FORMATS_ARR ) . Strings are returned unmodified .
def es_format_datetime(val):
    """
    Takes a date or datetime object and converts it to a format ES can read
    (see DATE_FORMATS_ARR). Strings are returned unmodified.
    """
    if isinstance(val, str):
        return val
    elif isinstance(val, datetime) and val.microsecond and val.tzinfo:
        # We don't support microsec precision with timezones
        return val.astimezone(timezone.utc).replace(tzinfo=None).isoformat()
    else:
        return val.isoformat()
def es_format_datetime ( val ) : if isinstance ( val , str ) : return val elif isinstance ( val , datetime ) and val . microsecond and val . tzinfo : # We don't support microsec precision with timezones return val . astimezone ( timezone . utc ) . replace ( tzinfo = None ) . isoformat ( ) else : return val . isoformat ( )