<commit_before># -*- coding: UTF-8 -*-
## Copyright 2011 <NAME>
## This file is part of the Lino project.
## Lino is free software; you can redistribute it and/or modify 
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
## Lino is distributed in the hope that it will be useful, 
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with Lino; if not, see <http://www.gnu.org/licenses/>.

"""
This module deserves more documentation.

"""

from django.utils.translation import ugettext_lazy as _

from lino.utils.choicelists import ChoiceList

class EventStatus(ChoiceList):
    """A list of possible values for the `status` field of an :class:`Event`.
    """
    label = _("Event Status")
    
add = EventStatus.add_item
add('0',en=u"tentative",de=u"Vorschlag",   fr=u"proposition")
add('1',en=u"confirmed",de=u"bestätigt",   fr=u"confirmé")
add('2',en=u"cancelled",de=u"storniert",   fr=u"annulé")

class TaskStatus(ChoiceList):
    """A list of possible values for the `status` field of a :class:`Task`.
    """
    label = _("Task Status")
    
add = TaskStatus.add_item
add('0',en=u"needs action",de=u"zu erledigen",   fr=u"à traîter")
add('1',en=u"in process",de=u"begonnen",   fr=u"commencée")
add('2',en=u"completed",de=u"erledigt",   fr=u"complétée")
add('3',en=u"cancelled",de=u"storniert",   fr=u"annulée")


def add_duration(dt,value,unit):
    if unit.value == 's' : 
        return dt + datetime.timedelta(seconds=value)
    if unit.value == 'm' : 
        return dt + datetime.timedelta(minutes=value)
    if unit.value == 'h' : 
        return dt + datetime.timedelta(hours=value)
    if unit.value == 'D' : 
        return dt + datetime.timedelta(days=value)
    if unit.value == 'W' : 
        return dt + datetime.timedelta(days=value*7)
    if unit.value == 'W' : 
        return dt + datetime.timedelta(days=value*7)
    day = dt.day
    while True:
        try:
            if unit.value == 'M' : 
                m = dt.month + value
                if m > 12: m -= 12
                return dt.replace(month=m,day=day)
            if unit.value == 'Y' : 
                return dt.replace(month=dt.year + value,day=day)
            raise Exception("Invalid DurationUnit %s" % unit)
        except ValueError:
            if day > 28:
                day -= 1
            else:
                raise
    

class DurationUnit(ChoiceList):<commit_msg>20110718<commit_after># -*- coding: UTF-8 -*-
## Copyright 2011 <NAME>
## This file is part of the Lino project.
## Lino is free software; you can redistribute it and/or modify 
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
## Lino is distributed in the hope that it will be useful, 
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with Lino; if not, see <http://www.gnu.org/licenses/>.

"""
This module deserves more documentation.

"""

from django.utils.translation import ugettext_lazy as _

from lino.utils.choicelists import ChoiceList

class EventStatus(ChoiceList):
    """A list of possible values for the `status` field of an :class:`Event`.
    """
    label = _("Event Status")
    
add = EventStatus.add_item
add('0',en=u"tentative",de=u"Vorschlag",   fr=u"proposition")
add('1',en=u"confirmed",de=u"bestätigt",   fr=u"confirmé")
add('2',en=u"cancelled",de=u"storniert",   fr=u"annulé")

class TaskStatus(ChoiceList):
    """A list of possible values for the `status` field of a :class:`Task`.
    """
    label = _("Task Status")
    
add = TaskStatus.add_item
add('0',en=u"needs action",de=u"zu erledigen",   fr=u"à traîter")
add('1',en=u"in process",de=u"begonnen",   fr=u"commencée")
add('2',en=u"completed",de=u"erledigt",   fr=u"complétée")
add('3',en=u"cancelled",de=u"storniert",   fr=u"annulée")


def add_duration(dt,value,unit):
    if unit.value == 's' : 
        return dt + datetime.timedelta(seconds=value)
    if unit.value == 'm' : 
        return dt + datetime.timedelta(minutes=value)
    if unit.value == 'h' : 
        return dt + datetime.timedelta(hours=value)
    if unit.value == 'D' : 
        return dt + datetime.timedelta(days=value)
    if unit.value == 'W' : 
        return dt + datetime.timedelta(days=value*7)
    if unit.value == 'W' : 
        return dt + datetime.timedelta(days=value*7)
    day = dt.day
    while True:
        try:
            if unit.value == 'M' : 
                m = dt.month + value
                if m > 12: m -= 12
                if m < 1: m += 12
                return dt.replace(month=m,day=day)
            if unit.value == 'Y' : 
                return dt.replace(month=dt.year + value,day=day)
            raise Exception("Invalid DurationUnit %s" % unit)
        except ValueError:
            if day > 28:
                day -= 1
            else:
                raise
    

class DurationUnit(ChoiceList):
{'fraction_non_alphanumeric': 0.13144850376353956, 'fraction_numerical': 0.01009730126675234, 'mean_word_length': 2.913793103448276, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4519584', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1714, 'n_words': 520}