dk.ttcal package

Submodules

dk.ttcal.calfns module

dk.ttcal.calfns.chop(it, n)[source]

Chop iterator into n size chuchks.

dk.ttcal.calfns.isoweek(year, week)[source]

Iterate over the days in isoweek week of year.

dk.ttcal.calfns.rangecmp()[source]

Compare half-open intervals [a, b) and [c, d) They compare equal if there is overlap.

dk.ttcal.calfns.rangetuple(x)[source]

dk.ttcal.day module

Date (single day) operations.

class dk.ttcal.day.Day[source]

Bases: datetime.date

A calendar date.

Month

Return a Month object representing the month self belongs to.

Year

Return a Year object representing the year self belongs to.

between_tuple()[source]

Return a tuple of datetimes that is convenient for sql between queries.

code

One letter code representing the dayname.

compare(other)[source]

Return how similar self is to other, i.e. the smallest factor they have in common (‘day’, ‘month’, or ‘year’). Returns None if the Days are in different years.

date()[source]

Excplicitly convert to datetime.date.

datetime(hour=0, minute=0, second=0)[source]

Extend self to datetime.

datetuple()[source]

Return year, month, day.

day_code = ['M', 'U', 'W', 'H', 'F', 'A', 'S']
day_name = [u'mandag', u'tirsdag', u'onsdag', u'torsdag', u'fredag', u'l\xf8rdag', u's\xf8ndag']
dayname

The semi-localized name of self.

display

Return the ‘class’ of self.

first

Define self == self.first for polymorphic usage with other classes.

format(fmt=None)[source]

Emulate Django’s date filter.

classmethod from_idtag(tag)[source]

Return Day from idtag.

static get_day_name(daynum, length=None)[source]

Return dayname for daynum.

idtag

Return the idtag for self: dyyyymmddmm.

in_month

True iff the day is in its month.

isoyear

Return the isoyear of self.

last

Define self == self.last for polymorphic usage with other classes.

middle

Return the day that splits the date range in half.

next()[source]

Return Tomorrow (for use in templates).

classmethod parse(strval)[source]

Parse date value from a string. Allowed syntax include

yyyy-mm-dd, yyyy-m-dd, yyyy-mm-d, yyyy-m-d
dd-mm-yyyy, etc.
dd/mm/yyyy, ...
dd.mm.yyyy, ...
ddmmyyyy
prev()[source]

Return Yesterday (for use in templates).

range()[source]

Return an iterator for the range of self.

rangetuple()[source]
special

True if the database has an entry for this date (sets special_hours).

timetuple()[source]

Create timetuple from datetuple. (to interact with datetime objects).

today

True if self is today.

week

Return a Week object representing the week self belongs to.

weekday

True if self is a weekday.

weekend

True if self is Saturday or Sunday.

weeknum

Return the isoweek of self.

class dk.ttcal.day.Days(start, end, start_week=False)[source]

Bases: list

A contigous set of days.

between_tuple()[source]

Return a tuple of datetimes that is convenient for sql between queries.

first

1st day

last

last day

middle

Return the day that splits the date range in half.

range()[source]

Return an iterator for the range of self.

class dk.ttcal.day.Today[source]

Bases: dk.ttcal.day.Day

Special subclass for today’s date.

today = True

dk.ttcal.duration module

Extension of datetime.timedelta.

class dk.ttcal.duration.Duration[source]

Bases: datetime.timedelta

A duration of time.

duration_tuple()[source]

Return self as hours, minutes, seconds.

hrs

The number of hours in self.

mins

The number of minutes in self.

classmethod parse(txt)[source]

Parse a textual representation into a Duration object. Format HHH:MM:SS.

secs

The number of seconds in self.

classmethod sum(sequence, start=None)[source]

Return the sum of sequence. (built-in sum only works with numbers).

toint()[source]

Convert self to integer.

dk.ttcal.month module

class dk.ttcal.month.Month(year=None, month=None, date=None)[source]

Bases: object

A calendar month.

Month
Year

Return a Year object for the year-part of this month.

between_tuple()[source]

Return a tuple of datetimes that is convenient for sql between queries.

datetuple()[source]

First date in month.

daycount

The number of days in this month (as an int).

dayiter()[source]
days()[source]

Return a list of days (class:ttcal.Day) in this month.

first

First day in month.

format(fmt=None)[source]

Format according to format string. Default format is monthname, four-digit-year.

classmethod from_date(d)[source]

Create a Month from the date d.

classmethod from_idtag(tag)[source]

Parse idtag into class:Month.

idtag()[source]

Return a text representation that is parsable by the from_idtag function (above), and is useable as part of an url.

last

Last day in month.

mark(d, value='mark', method='replace')[source]
marked_days()[source]
middle

Return the day that splits the date range in half.

month = None
month_name = ['', 'Januar', 'Februar', 'Mars', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Desember']
next()[source]

Next month.

numdays()[source]

The number of days in the month.

classmethod parse(txt)[source]

Parse a textual representation into a Month object. Format YYYY-MM?

prev()[source]

Previous month.

range()[source]

Return an iterator for the range of self.

rangetuple()[source]
timetuple()[source]

Create timetuple from datetuple. (to interact with datetime objects).

year = None

dk.ttcal.week module

class dk.ttcal.week.Week(days, month)[source]

Bases: object

between_tuple()[source]

Return a tuple of datetimes that is convenient for sql between queries.

current

True if today is in week.

datetuple()[source]

First day of this week.

days = None
first

1st day of week.

classmethod from_idtag(tag)[source]
idtag()[source]
last

Last day of week.

middle

Return the day that splits the date range in half.

month = None
num = None
range()[source]

Return an iterator for the range of self.

rangetuple()[source]
until_today()[source]
classmethod weeknum(n=None, year=None)[source]
year = None

dk.ttcal.year module

class dk.ttcal.year.Year(year=None)[source]

Bases: object

H1

First half of this year.

H2

Last half of this year.

Month

For orthogonality in the api.

Q1

1st quarter.

Q2

2nd quarter.

Q3

3rd quarter.

Q4

4th quarter.

Year
april
august
between_tuple()[source]

Return a tuple of datetimes that is convenient for sql between queries.

datetuple()[source]

January 1.

dayiter()[source]
december
february
first

First day of first month.

format(fmt=None)[source]

Format according to format string. Default format is monthname, four-digit-year.

classmethod from_idtag(tag)[source]

Year tags have the lower-case letter y + the four digit year, eg. y2008.

halves()[source]

Both halves of the year.

idtag()[source]

Year tags have the lower-case letter y + the four digit year, eg. y2008.

january
july
june
last

Last day of last month.

march
mark(d, value='mark')[source]
mark_period(p, value='mark')[source]
marked_days()[source]
may
middle

Return the day that splits the date range in half.

next()[source]

Next year.

november
october
prev()[source]

Previous year.

quarters()[source]

Every quarter in this year.

range()[source]

Return an iterator for the range of self.

rangetuple()[source]
rows()[source]
rows4()[source]
september
timetuple()[source]

Module contents

Date classes (originally from TikTok).

dk.ttcal.from_idtag(idtag)[source]

Return a class from idtag.