libestg3b

libestg3b.EStG3b(country)[source]

Get the implementation class for the given country.

Parameters:country (str) – ISO short code of the desired country, e.g. "DE"
Return type:Type[EStG3bBase]
libestg3b.EStG3bs()[source]

Get a list containing implementation classes for all implemented countries.

Return type:List[Type[EStG3bBase]]
class libestg3b.EStG3bBase(country, groups, add_rules=None, replace_rules=None)[source]

Bases: object

calculate_shift(shift)[source]

Turn a shift into a number of matches, containing the relevant rules (if any), which can be used to calculate the appropriate high of bonus payments.

>>> import datetime as DT
>>> from libestg3b import EStG3b
>>> e = EStG3b("DE")
>>> e.calculate_shift([DT.datetime(2018, 12, 24, 13), DT.datetime(2018, 12, 25, 2)])
[
    Match(start=datetime.datetime(2018, 12, 24, 13, 0), end=datetime.datetime(2018, 12, 24, 14, 0), rules=set(
    )),
    Match(start=datetime.datetime(2018, 12, 24, 14, 0), end=datetime.datetime(2018, 12, 24, 20, 0), rules={
        <Rule: DE_HEILIGABEND YYYY-12-24 14:00+>
    }),
    Match(start=datetime.datetime(2018, 12, 24, 20, 0), end=datetime.datetime(2018, 12, 25, 0, 0), rules={
        <Rule: DE_HEILIGABEND YYYY-12-24 14:00+>,
        <Rule: DE_NIGHT Nachtarbeit 20:00-06:00>
    }),
    Match(start=datetime.datetime(2018, 12, 25, 0, 0), end=datetime.datetime(2018, 12, 25, 2, 0), rules={
        <Rule: DE_WEIHNACHTSFEIERTAG_1 YYYY-12-25>,
        <Rule: DE_NIGHT_START_YESTERDAY Nachtarbeit 00:00-04:00 (Folgetag)>
    })
]
Parameters:shift (Tuple[datetime, datetime]) – a (starttime, endtime) tuple. Describes a shift started and starttime (inclusive) and ending at endtime (exclusive).
Return type:List[Match]
calculate_shifts(shifts)[source]

Behaves similar to calculate_shift(), but takes a list of shifts and returns a list of matches. It also merges any shifts that overlap, resulting in a clean list of matches.

Parameters:shifts (List[Tuple[datetime, datetime]]) –
Return type:Iterator[Match]
class libestg3b.Match(start, end, rules)[source]

Bases: object

The final result of the calculation process. It links time worked to additional payments (or the information that none are relevant).

Parameters:
  • start (datetime) – the (inclusive) time this shift part starts at
  • end (datetime) – the (exclusive) time this shift part ends at
  • rules (Set[Rule]) – all the relevant Rule instances. May be empty to indicate, that no match has been found.
rules_str

a human-readable representation of all the rules matched, e.g. DE_NIGHT+DE_SUNDAY

Return type:str
bonus_multiply

the height of the bonus, as a factor to add e.g. Decimal(0.2) => 20%.

Return type:Decimal
bonus_add

the total amount of monetary units to add as a bonus, e.g. Decimal(5) => 5€.

Return type:Decimal
minutes

the number of minutes this Match covers, e.g. Decimal(180) => 3h.

Return type:Decimal