MCPcopy Create free account
hub / github.com/dateutil/dateutil / replace

Method replace

src/dateutil/tz/_common.py:68–96  ·  view source on GitHub ↗

Return a datetime with the same attributes, except for those attributes given new values by whichever keyword arguments are specified. Note that tzinfo=None can be specified to create a naive datetime from an aware datetime with no conversion of date

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

66 __slots__ = ()
67
68 def replace(self, *args, **kwargs):
69 """
70 Return a datetime with the same attributes, except for those
71 attributes given new values by whichever keyword arguments are
72 specified. Note that tzinfo=None can be specified to create a naive
73 datetime from an aware datetime with no conversion of date and time
74 data.
75
76 This is reimplemented in ``_DatetimeWithFold`` because pypy3 will
77 return a ``datetime.datetime`` even if ``fold`` is unchanged.
78 """
79 argnames = (
80 'year', 'month', 'day', 'hour', 'minute', 'second',
81 'microsecond', 'tzinfo'
82 )
83
84 for arg, argname in zip(args, argnames):
85 if argname in kwargs:
86 raise TypeError('Duplicate argument: {}'.format(argname))
87
88 kwargs[argname] = arg
89
90 for argname in argnames:
91 if argname not in kwargs:
92 kwargs[argname] = getattr(self, argname)
93
94 dt_class = self.__class__ if kwargs.get('fold', 1) else datetime
95
96 return dt_class(**kwargs)
97
98 @property
99 def fold(self):

Callers 15

get_tokenMethod · 0.45
parseMethod · 0.45
_build_tzawareMethod · 0.45
_build_naiveMethod · 0.45
_find_compMethod · 0.45
nocacheMethod · 0.45
datetime_existsFunction · 0.45
datetime_ambiguousFunction · 0.45
_datetime_to_timestampFunction · 0.45
picknthweekdayFunction · 0.45
enfoldFunction · 0.45
is_ambiguousMethod · 0.45

Calls 1

getMethod · 0.45

Tested by

no test coverage detected