Goulib.datetime2 module¶
additions to datetime
standard library
-
class
Goulib.datetime2.
datetime2
(*args, **kwargs)[source]¶ Bases:
datetime.datetime
-
__add__
¶ Return self+value.
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dir__
()¶ Default dir() implementation.
-
__eq__
¶ Return self==value.
-
__format__
()¶ Formats self with strftime.
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__radd__
¶ Return value+self.
-
__reduce__
() -> (cls, state)¶
-
__reduce_ex__
(proto) -> (cls, state)¶
-
__repr__
¶ Return repr(self).
-
__rsub__
¶ Return value-self.
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
()¶ Size of object in memory, in bytes.
-
__str__
¶ Return str(self).
-
astimezone
()¶ tz -> convert to local time in new timezone tz
-
combine
()¶ date, time -> datetime with same date and time fields
-
ctime
()¶ Return ctime() style string.
-
date
()¶ Return date object with same year, month and day.
-
day
¶
-
dst
()¶ Return self.tzinfo.dst(self).
-
fold
¶
-
fromisoformat
()¶ string -> datetime from datetime.isoformat() output
-
fromordinal
()¶ int -> date corresponding to a proleptic Gregorian ordinal.
-
fromtimestamp
()¶ timestamp[, tz] -> tz’s local time from POSIX timestamp.
-
hour
¶
-
isocalendar
()¶ Return a 3-tuple containing ISO year, week number, and weekday.
-
isoformat
()¶ [sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]. sep is used to separate the year from the time, and defaults to ‘T’. timespec specifies what components of the time to include (allowed values are ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’, and ‘microseconds’).
-
isoweekday
()¶ Return the day of the week represented by the date. Monday == 1 … Sunday == 7
-
max
= datetime.datetime(9999, 12, 31, 23, 59, 59, 999999)¶
-
microsecond
¶
-
min
= datetime.datetime(1, 1, 1, 0, 0)¶
-
minute
¶
-
month
¶
-
now
()¶ Returns new datetime object representing current time local to tz.
- tz
- Timezone object.
If no tz is specified, uses local timezone.
-
replace
()¶ Return datetime with new specified fields.
-
resolution
= datetime.timedelta(microseconds=1)¶
-
second
¶
-
strftime
()¶ format -> strftime() style string.
-
strptime
()¶ string, format -> new datetime parsed from a string (like time.strptime()).
-
time
()¶ Return time object with same time but with tzinfo=None.
-
timestamp
()¶ Return POSIX timestamp as float.
-
timetuple
()¶ Return time tuple, compatible with time.localtime().
-
timetz
()¶ Return time object with same time and tzinfo.
-
today
()¶ Current date or datetime: same as self.__class__.fromtimestamp(time.time()).
-
toordinal
()¶ Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.
-
tzinfo
¶
-
tzname
()¶ Return self.tzinfo.tzname(self).
-
utcfromtimestamp
()¶ Construct a naive UTC datetime from a POSIX timestamp.
-
utcnow
()¶ Return a new datetime representing UTC day and time.
-
utcoffset
()¶ Return self.tzinfo.utcoffset(self).
-
utctimetuple
()¶ Return UTC time tuple, compatible with time.localtime().
-
weekday
()¶ Return the day of the week represented by the date. Monday == 0 … Sunday == 6
-
year
¶
-
-
class
Goulib.datetime2.
date2
[source]¶ Bases:
datetime.date
-
__add__
¶ Return self+value.
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dir__
()¶ Default dir() implementation.
-
__eq__
¶ Return self==value.
-
__format__
()¶ Formats self with strftime.
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__radd__
¶ Return value+self.
-
__reduce__
() -> (cls, state)¶
-
__reduce_ex__
()¶ Helper for pickle.
-
__repr__
¶ Return repr(self).
-
__rsub__
¶ Return value-self.
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
()¶ Size of object in memory, in bytes.
-
__str__
¶ Return str(self).
-
__sub__
¶ Return self-value.
-
ctime
()¶ Return ctime() style string.
-
day
¶
-
fromisoformat
()¶ str -> Construct a date from the output of date.isoformat()
-
fromordinal
()¶ int -> date corresponding to a proleptic Gregorian ordinal.
-
fromtimestamp
()¶ timestamp -> local date from a POSIX timestamp (like time.time()).
-
isocalendar
()¶ Return a 3-tuple containing ISO year, week number, and weekday.
-
isoformat
()¶ Return string in ISO 8601 format, YYYY-MM-DD.
-
isoweekday
()¶ Return the day of the week represented by the date. Monday == 1 … Sunday == 7
-
max
= datetime.date(9999, 12, 31)¶
-
min
= datetime.date(1, 1, 1)¶
-
month
¶
-
replace
()¶ Return date with new specified fields.
-
resolution
= datetime.timedelta(days=1)¶
-
strftime
()¶ format -> strftime() style string.
-
timetuple
()¶ Return time tuple, compatible with time.localtime().
-
today
()¶ Current date or datetime: same as self.__class__.fromtimestamp(time.time()).
-
toordinal
()¶ Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.
-
weekday
()¶ Return the day of the week represented by the date. Monday == 0 … Sunday == 6
-
year
¶
-
-
class
Goulib.datetime2.
time2
(*args, **kwargs)[source]¶ Bases:
datetime.time
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dir__
()¶ Default dir() implementation.
-
__eq__
¶ Return self==value.
-
__format__
()¶ Formats self with strftime.
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
() -> (cls, state)¶
-
__reduce_ex__
(proto) -> (cls, state)¶
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
()¶ Size of object in memory, in bytes.
-
__str__
¶ Return str(self).
-
dst
()¶ Return self.tzinfo.dst(self).
-
fold
¶
-
fromisoformat
()¶ string -> time from time.isoformat() output
-
hour
¶
-
isoformat
()¶ Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].
timespec specifies what components of the time to include.
-
max
= datetime.time(23, 59, 59, 999999)¶
-
microsecond
¶
-
min
= datetime.time(0, 0)¶
-
minute
¶
-
replace
()¶ Return time with new specified fields.
-
resolution
= datetime.timedelta(microseconds=1)¶
-
second
¶
-
strftime
()¶ format -> strftime() style string.
-
tzinfo
¶
-
tzname
()¶ Return self.tzinfo.tzname(self).
-
utcoffset
()¶ Return self.tzinfo.utcoffset(self).
-
-
class
Goulib.datetime2.
timedelta2
(*args, **kwargs)[source]¶ Bases:
datetime.timedelta
-
__abs__
¶ abs(self)
-
__add__
¶ Return self+value.
-
__bool__
¶ self != 0
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dir__
()¶ Default dir() implementation.
-
__divmod__
¶ Return divmod(self, value).
-
__eq__
¶ Return self==value.
-
__floordiv__
¶ Return self//value.
-
__format__
()¶ Default object formatter.
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__mod__
¶ Return self%value.
-
__mul__
¶ Return self*value.
-
__ne__
¶ Return self!=value.
-
__neg__
¶ -self
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__pos__
¶ +self
-
__radd__
¶ Return value+self.
-
__rdivmod__
¶ Return divmod(value, self).
-
__reduce__
() -> (cls, state)¶
-
__reduce_ex__
()¶ Helper for pickle.
-
__repr__
¶ Return repr(self).
-
__rfloordiv__
¶ Return value//self.
-
__rmod__
¶ Return value%self.
-
__rmul__
¶ Return value*self.
-
__rsub__
¶ Return value-self.
-
__rtruediv__
¶ Return value/self.
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
()¶ Size of object in memory, in bytes.
-
__str__
¶ Return str(self).
-
__sub__
¶ Return self-value.
-
__truediv__
¶ Return self/value.
-
days
¶ Number of days.
-
max
= datetime.timedelta(days=999999999, seconds=86399, microseconds=999999)¶
-
microseconds
¶ Number of microseconds (>= 0 and less than 1 second).
-
min
= datetime.timedelta(days=-999999999)¶
-
resolution
= datetime.timedelta(microseconds=1)¶
-
seconds
¶ Number of seconds (>= 0 and less than 1 day).
-
total_seconds
()¶ Total seconds in the duration.
-
-
Goulib.datetime2.
datetimef
(d, t=None, fmt='%Y-%m-%d')[source]¶ “converts something to a datetime :param d: can be:
- datetime : result is a copy of d with time optionally replaced
- date : result is date at time t, (00:00AM by default)
- int or float : if fmt is None, d is considered as Excel date numeric format (see http://answers.oreilly.com/topic/1694-how-excel-stores-date-and-time-values/ )
- string or specified format: result is datetime parsed using specified format string
Parameters: - fmt – format string. See http://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
- t – optional time. replaces the time of the datetime obtained from d. Allows datetimef(date,time)
Returns: datetime
-
Goulib.datetime2.
fmt2regex
(fmt)[source]¶ converts a date/time format string to the regex that comiles it
Parameters: fmt – string Returns: compiled regex
-
Goulib.datetime2.
timedeltaf
(t, fmt=None)[source]¶ converts something to a timedelta.
Parameters: t – can be: - already a timedelta, or a time, or a int/float giving a number of days (Excel)
- or a string in HH:MM:SS format by default
- or a string in timedelta str() output format
-
Goulib.datetime2.
strftimedelta
(t, fmt='%H:%M:%S')[source]¶ Parameters: t – float seconds or timedelta
-
Goulib.datetime2.
daysgen
(start, length, step=datetime.timedelta(days=1))[source]¶ returns a range of dates or datetimes
-
Goulib.datetime2.
timedelta_div
(t1, t2)[source]¶ divides a timedelta by a timedelta or a number. should be a method of timedelta…
-
Goulib.datetime2.
timedelta_mul
(t1, t2)[source]¶ multiplies a timedelta. should be a method of timedelta…
-
Goulib.datetime2.
equal
(a, b, epsilon=datetime.timedelta(microseconds=500000))[source]¶ approximately equal. Use this instead of a==b :return: True if a and b are less than seconds apart