# Path: khayyam/formatting/directives/base.py
# class Directive(object):
#     """
#     Base class for all formatting directives.
# 
#     """
# 
#     def __init__(self, key, name, regex, type_, formatter=None, post_parser=None):
#         self.key = key
#         self.name = name
#         self.regex = regex
#         self.type_ = type_
#         if formatter:
#             self.format = formatter
#         if post_parser:
#             self.post_parser = post_parser
# 
#     def __repr__(self):  # pragma: no cover
#         return '%' + self.key
# 
#     def post_parser(self, ctx, formatter):  # pragma: no cover
#         """
#         In overridden method, It should parse the formatted value from the given string.
#         :param ctx:
#         :param formatter:
#         :return:
#         """
#         pass
# 
#     def format(self, d):  # pragma: no cover
#         """
#         In overridden method, It Should return string representation of the given argument.
# 
#         :param d: a value to format
#         :return: Formatted value.
#         :rtype: str
#         """
#         return d
# 
# Path: khayyam/formatting/directives/persian.py
# class PersianNumberDirective(Directive):
#     """
#     Representing a number in persian form.
#     """
#     def __init__(self, key, name, regex, zero_padding=False, zero_padding_length=2):
#         self.zero_padding = zero_padding
#         self.zero_padding_length = zero_padding_length
#         super(PersianNumberDirective, self).__init__(key, name, regex, get_unicode)
# 
#     def format(self, i):
#         if self.zero_padding:
#             fmt = '%%.%dd' % self.zero_padding_length
#             return eng_to_persian(fmt % i)
#         elif isinstance(i, int):
#             return eng_to_persian(str(i))
#         else:
#             return eng_to_persian(i)
# 
#     def post_parser(self, ctx, formatter):
#         exp = ctx[self.name]
#         if exp.strip() != '':
#             ctx[self.name] = int(persian_to_eng(exp))
# 
# Path: khayyam/algorithms.py



from .base import Directive
from .persian import PersianNumberDirective
from khayyam.algorithms import get_days_in_jalali_year
from datetime import timedelta
        from khayyam import JalaliDate
    """
    Representing a day in persian calendar.
    """

    def format(self, d):
        return super(PersianDayDirective, self).format(d.day)

    def post_parser(self, ctx, formatter):
        super(PersianDayDirective, self).post_parser(ctx, formatter)
        if self.name in ctx and ctx[self.name]:
            ctx['day'] = ctx[self.name]


class DayOfYearDirective(Directive):
    """
    Representing day of year.
    """

    def format(self, d):
        return '%.3d' % d.dayofyear()

    def post_parser(self, ctx, formatter):
        _dayofyear = ctx['dayofyear']
        if 'year' not in ctx:
            ctx['year'] = 1
        if 'month' in ctx:
            del ctx['month']
        if 'day' in ctx:
            del ctx['day']


# Path: khayyam/formatting/directives/base.py
# class Directive(object):
#     """
#     Base class for all formatting directives.
# 
#     """
# 
#     def __init__(self, key, name, regex, type_, formatter=None, post_parser=None):
#         self.key = key
#         self.name = name
#         self.regex = regex
#         self.type_ = type_
#         if formatter:
#             self.format = formatter
#         if post_parser:
#             self.post_parser = post_parser
# 
#     def __repr__(self):  # pragma: no cover
#         return '%' + self.key
# 
#     def post_parser(self, ctx, formatter):  # pragma: no cover
#         """
#         In overridden method, It should parse the formatted value from the given string.
#         :param ctx:
#         :param formatter:
#         :return:
#         """
#         pass
# 
#     def format(self, d):  # pragma: no cover
#         """
#         In overridden method, It Should return string representation of the given argument.
# 
#         :param d: a value to format
#         :return: Formatted value.
#         :rtype: str
#         """
#         return d
# 
# Path: khayyam/formatting/directives/persian.py
# class PersianNumberDirective(Directive):
#     """
#     Representing a number in persian form.
#     """
#     def __init__(self, key, name, regex, zero_padding=False, zero_padding_length=2):
#         self.zero_padding = zero_padding
#         self.zero_padding_length = zero_padding_length
#         super(PersianNumberDirective, self).__init__(key, name, regex, get_unicode)
# 
#     def format(self, i):
#         if self.zero_padding:
#             fmt = '%%.%dd' % self.zero_padding_length
#             return eng_to_persian(fmt % i)
#         elif isinstance(i, int):
#             return eng_to_persian(str(i))
#         else:
#             return eng_to_persian(i)
# 
#     def post_parser(self, ctx, formatter):
#         exp = ctx[self.name]
#         if exp.strip() != '':
#             ctx[self.name] = int(persian_to_eng(exp))
# 
# Path: khayyam/algorithms.py



# Path: khayyam/formatting/directives/day.py
from .base import Directive
from .persian import PersianNumberDirective
from khayyam.algorithms import get_days_in_jalali_year
from datetime import timedelta
        from khayyam import JalaliDate

    """
    Representing a day in persian calendar.
    """

    def format(self, d):
        return super(PersianDayDirective, self).format(d.day)

    def post_parser(self, ctx, formatter):
        super(PersianDayDirective, self).post_parser(ctx, formatter)
        if self.name in ctx and ctx[self.name]:
            ctx['day'] = ctx[self.name]


class DayOfYearDirective(Directive):
    """
    Representing day of year.
    """

    def format(self, d):
        return '%.3d' % d.dayofyear()

    def post_parser(self, ctx, formatter):
        _dayofyear = ctx['dayofyear']
        if 'year' not in ctx:
            ctx['year'] = 1
        if 'month' in ctx:
            del ctx['month']
        if 'day' in ctx:
            del ctx['day']


        max_days = get_days_in_jalali_year(ctx['year'])