def convert_type(string, field_type, close_period=True):
    if string == '':
        raise ValidationError({
            "message":
            "Attempting to convert an empty string to a date format"
        })
    if field_type in ('DateTimeField', 'DateField'):
        if field_type == 'DateTimeField':
            # Expected format YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]
            dt = ensure_pendulum(string)
            if close_period:
                dt.end_of('day')
            else:
                dt.start_of('day')
            return format_datetime(dt)
        if field_type == 'DateField':
            # Expected YYYY-MM-DD
            dt = ensure_pendulum(string)
            # Deactivated by lco, a date is a date, no time in it
            # if close_period:
            #     dt.end_of('day')
            return dt.to_date_string()
    elif field_type in ('DecimalField', 'FloatField'):
        return float(string)
    else:
        return int(string)
 def test_parse_string(self):
     now = timezone.now()
     d1 = ensure_pendulum(str(now))
     d2 = ensure_pendulum(now)
     self.assertEqual(format_datetime(d1), format_datetime(d2))