# -*- coding: utf-8 mode: python -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8

__all__ = ('JourF',)

from ..uio import _s

from .strings import UnicodeF

class JourF(UnicodeF):
    LUNDI = u"lundi"
    MARDI = u"mardi"
    MERCREDI = u"mercredi"
    JEUDI = u"jeudi"
    VENDREDI = u"vendredi"
    SAMEDI = u"samedi"
    DIMANCHE = u"dimanche"

    JOURS = [j.capitalize() for j in (LUNDI, MARDI, MERCREDI, JEUDI, VENDREDI, SAMEDI, DIMANCHE)]
    JOUR_MAP = {u"1": LUNDI, u"l": LUNDI, u"lun": LUNDI,
                u"2": MARDI, u"ma": MARDI, u"mar": MARDI,
                u"3": MERCREDI, u"me": MERCREDI, u"mer": MERCREDI,
                u"4": JEUDI, u"j": JEUDI, u"jeu": JEUDI,
                u"5": VENDREDI, u"v": VENDREDI, u"ven": VENDREDI,
                u"6": SAMEDI, u"s": SAMEDI, u"sam": SAMEDI,
                u"0": DIMANCHE, u"7": DIMANCHE, u"d": DIMANCHE, u"dim": DIMANCHE,
                }

    def parse(self, s):
        s = UnicodeF.parse(self, s)
        if s is None: return None

        j = self.RE_SPACES.sub(u'', s)
        j = self.JOUR_MAP.get(j.lower(), j).capitalize()
        if j in self.JOURS: return j
        else: raise ValueError("Invalid day name: %s" % s)

    def format(self, j):
        if j is None: return u""
        else: return j

    def get_dow(self, j):
        return self.JOURS.index(j)
