Turn obj.value into a datetime.timedelta.
351744
def transformToNative(obj):
        
        if obj.isNative:
            return obj
        obj.isNative = True
        obj.value=obj.value
        if obj.value == '':
            return obj
        else:
            deltalist=stringToDurations(obj.value)
            # When can DURATION have multiple durations?  For now:
            if len(deltalist) == 1:
                obj.value = deltalist[0]
                return obj
            else:
                raise ParseError("DURATION must have a single duration string.")
1163058
def dateadd(value: fields.DateTime(),
            addend: fields.Int(validate=Range(min=1)),
            unit: fields.Str(validate=OneOf(['minutes', 'days']))='days'):
    """"""
    value = value or dt.datetime.utcnow()
    if unit == 'minutes':
        delta = dt.timedelta(minutes=addend)
    else:
        delta = dt.timedelta(days=addend)
    result = value + delta
    return {'result': result}
18838
def format_item(x, timedelta_format=None, quote_strings=True):
    """"""
    if isinstance(x, (np.datetime64, datetime)):
        return format_timestamp(x)
    if isinstance(x, (np.timedelta64, timedelta)):
        return format_timedelta(x, timedelta_format=timedelta_format)
    elif isinstance(x, (str, bytes)):
        return repr(x) if quote_strings else x
    elif isinstance(x, (float, np.float)):
        return '{0:.4}'.format(x)
    else:
        return str(x)
354786
def datetime(anon, obj, field, val):
    
    return anon.faker.datetime(field=field)
142867
def to_datetime_with_default(value, default_value):
        
        result = DateTimeConverter.to_nullable_datetime(value)
        return result if result != None else DateTimeConverter.to_utc_datetime(default_value)
543377
def convert_dict_to_datetime(obj_map):
    """"""
    converted_map = {}
    for key, value in obj_map.items():
        if isinstance(value, dict) and 'tzinfo' in value.keys():
            converted_map[key] = datetime.datetime(**value)
        elif isinstance(value, dict):
            converted_map[key] = convert_dict_to_datetime(value)
        elif isinstance(value, list):
            updated_list = []
            for internal_item in value:
                if isinstance(internal_item, dict):
                    updated_list.append(convert_dict_to_datetime(internal_item))
                else:
                    updated_list.append(internal_item)
            converted_map[key] = updated_list
        else:
            converted_map[key] = value
    return converted_map
193862
def floating_point_to_datetime(day, fp_time):
    """"""
    result = datetime(year=day.year, month=day.month, day=day.day)
    result += timedelta(minutes=math.ceil(60 * fp_time))
    return result
805866
def _cast(self, value, format=None, **opts):
        """"""
        if format is not None:
            return datetime.strptime(value, format)
        return dateutil.parser.parse(value)
1129555
def date_to_datetime(x):
    """"""
    if not isinstance(x, datetime) and isinstance(x, date):
        return datetime.combine(x, time())
    return x
1161938
def simple_time(value):
    
    if isinstance(value, timedelta):
        return ':'.join(str(value).split(':')[:2])
    return datetime_to_string(value, '%H:%M')
902065
def to_utc_datetime(self, value):
        
        value = self.to_naive_datetime(value)

        if timezone.is_naive(value):
            value = timezone.make_aware(value, timezone.utc)
        else:
            value = timezone.localtime(value, timezone.utc)
        return value
302225
def parse_value(self, value):
        """"""
        if value is None:
            return value
        if isinstance(value, datetime.time):
            return value
        return parse(value).timetz()
787898
def _clean_datetime(self, obj):
        """"""
        if isinstance(obj, datetime):
            # if it's not naive, put it on zulu time first:
            if obj.tzinfo is not None:
                obj = obj.astimezone(pytz.utc)
            return obj.isoformat()[:self.MAX_LENGTH]
        if isinstance(obj, date):
            return obj.isoformat()
354255
def transformToNative(obj):
        
        if obj.isNative:
            return obj
        value = getattr(obj, 'value_param', 'DURATION').upper()
        if hasattr(obj, 'value_param'):
            del obj.value_param
        if obj.value == '':
            obj.isNative = True
            return obj
        elif value  == 'DURATION':
            try:
                return Duration.transformToNative(obj)
            except ParseError:
                logger.warning("TRIGGER not recognized as DURATION, trying "
                             "DATE-TIME, because iCal sometimes exports "
                             "DATE-TIMEs without setting VALUE=DATE-TIME")
                try:
                    obj.isNative = False
                    dt = DateTimeBehavior.transformToNative(obj)
                    return dt
                except:
                    msg = "TRIGGER with no VALUE not recognized as DURATION " \
                          "or as DATE-TIME"
                    raise ParseError(msg)
        elif value == 'DATE-TIME':
            # TRIGGERs with DATE-TIME values must be in UTC, we could validate
            # that fact, for now we take it on faith.
            return DateTimeBehavior.transformToNative(obj)
        else:
            raise ParseError("VALUE must be DURATION or DATE-TIME")
470939
def similar_datetime(anon, obj, field, val):
    
    return anon.faker.datetime(field=field, val=val)
1356205
def inc_date(date_obj, num, date_fmt):
    
    return (date_obj + timedelta(days=num)).strftime(date_fmt)
861474
def _serializer(obj):
    '''
    
    '''
    import datetime
    if isinstance(obj, datetime.datetime):
        if obj.utcoffset() is not None:
            obj = obj - obj.utcoffset()
        return obj.__str__()
    return obj