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

__all__ = ('DateF', 'DateProperty',
           'TimeF', 'TimeProperty',
           )

from ulib.base.dates import ensure_date, FR_DATEF
from ulib.base.times import ensure_time, HM_TIMEF

from base import Format

class DateF(Format):
    format_string = None

    def __init__(self, format_string=None):
        if format_string is None: format_string = FR_DATEF
        self.format_string = format_string

    def parse(self, s):
        if s is None: return None
        else: return ensure_date(s)

    def format(self, d):
        if d is None: return u""
        else: return d.format(self.format_string)

class TimeF(Format):
    format_string = None

    def __init__(self, format_string=None):
        if format_string is None: format_string = HM_TIMEF
        self.format_string = format_string

    def parse(self, s):
        if s is None: return None
        else: return ensure_time(s)

    def format(self, t):
        if t is None: return u""
        else: return t.format(self.format_string)
