Goulib.datetime2 module

additions to datetime standard library

class Goulib.datetime2.datetime2(*args, **kwargs)[source]

Bases: datetime.datetime

__init__(*args, **kwargs)[source]
__sub__(other)[source]
__add__

Return self+value.

__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

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).

__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__() → int

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).

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-DDTHH:MM:SS[.mmmmmm][+HH:MM].

sep is used to separate the year from the time, and defaults to ‘T’.

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(0, 0, 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

init__(*args, **kwargs)[source]
__add__

Return self+value.

__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

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.

__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__() → int

size of object in memory, in bytes

__str__

Return str(self).

__sub__

Return self-value.

ctime()

Return ctime() style string.

day
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(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

__init__(*args, **kwargs)[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

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).

__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__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

dst()

Return self.tzinfo.dst(self).

hour
isoformat()

Return string in ISO 8601 format, HH:MM:SS[.mmmmmm][+HH:MM].

max = datetime.time(23, 59, 59, 999999)
microsecond
min = datetime.time(0, 0)
minute
replace()

Return time with new specified fields.

resolution = datetime.timedelta(0, 0, 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

__init__(*args, **kwargs)[source]
isoformat()[source]
__abs__

abs(self)

__add__

Return self+value.

__bool__

self != 0

__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

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).

__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__() → int

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(999999999, 86399, 999999)
microseconds

Number of microseconds (>= 0 and less than 1 second).

min = datetime.timedelta(-999999999)
resolution = datetime.timedelta(0, 0, 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:

Parameters:
Returns:

datetime

Goulib.datetime2.datef(d, fmt='%Y-%m-%d')[source]

converts something to a date. See datetimef

Goulib.datetime2.timef(t, fmt='%H:%M:%S')[source]

converts something to a time. See datetimef

Goulib.datetime2.timedeltaf(t, fmt=None)[source]

converts something to a timedelta. :param 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.tdround(td, s=1)[source]

return timedelta rounded to s seconds

Goulib.datetime2.minutes(td)[source]
Parameters:td – timedelta
Returns:float timedelta in minutes
Goulib.datetime2.hours(td)[source]
Parameters:td – timedelta
Returns:float timedelta in hours
Goulib.datetime2.daysgen(start, length, step=datetime.timedelta(1))[source]

returns a range of dates or datetimes

Goulib.datetime2.days(start, length, step=datetime.timedelta(1))[source]
Goulib.datetime2.timedelta_sum(timedeltas)[source]
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.time_sub(t1, t2)[source]

substracts 2 time. should be a method of time...

Goulib.datetime2.time_add(t, d)[source]

adds delta to time. should be a method of time...

Goulib.datetime2.add_months(date, months)[source]
Goulib.datetime2.date_add(date, years=0, months=0, weeks=0, days=0)[source]
Goulib.datetime2.equal(a, b, epsilon=datetime.timedelta(0, 0, 500000))[source]

approximately equal. Use this instead of a==b :return: True if a and b are less than seconds apart

Goulib.datetime2.datetime_intersect(t1, t2)[source]

returns timedelta overlap between 2 intervals (tuples) of datetime

Goulib.datetime2.time_intersect(t1, t2)[source]

returns timedelta overlap between 2 intervals (tuples) of time