# Path: core/util.py
# def nonone(value, replace_value):
#     """Returns ``value`` if ``value`` is not ``None``. Returns ``replace_value`` otherwise.
#     """
#     if value is None:
#         return replace_value
#     else:
#         return value
# 
# Path: core/model/date.py
# def parse_date(string, format):
#     """Parses ``string`` into a ``datetime.date`` using ``format`` (ISO).
# 
#     .. seealso:: :class:`DateFormat`
#     """
#     return DateFormat(format).parse_date(string)
# 
# def format_date(date, format):
#     """Formats ``date`` using ``format`` (ISO).
# 
#     .. seealso:: :class:`DateFormat`
#     """
#     return format_year_month_day(date.year, date.month, date.day, format)


import os
import os.path as op
from core.util import nonone
from .gui.date_widget import DateWidget
from .model import currency
from .model._ccore import amount_configure
from .model.currency import Currencies
from .model.currency_provider import get_providers
from .model.date import parse_date, format_date
            if not op.exists(cache_path):
                os.makedirs(cache_path)
            db_path = op.join(cache_path, 'currency.db')
        else:
            db_path = ':memory:'
        currency.initialize_db(db_path)
        self._default_currency = default_currency
        self._date_format = date_format
        amount_configure(decimal_sep, grouping_sep)
        self._autosave_interval = self.get_default(PreferenceNames.AutoSaveInterval, 10)
        self._auto_decimal_place = self.get_default(PreferenceNames.AutoDecimalPlace, False)
        self._day_first_date_entry = self.get_default(PreferenceNames.DayFirstDateEntry, True)
        self._show_schedule_scope_dialog = self.get_default(PreferenceNames.ShowScheduleScopeDialog, True)
        self._hook_currency_providers()
        self._update_date_entry_order()

    # --- Private
    def _update_date_entry_order(self):
        DateWidget.setDMYEntryOrder(self._day_first_date_entry)

    def _hook_currency_providers(self):
        for p in get_providers():
            Currencies.get_rates_db().register_rate_provider(p().wrapped_get_currency_rates)

    # --- Public
    def format_date(self, date):
        """Returns a formatted date using app-wide preferences.

        This simply wraps :func:`core.model.date.format_date` and adds default values.
        """

# Path: core/util.py
# def nonone(value, replace_value):
#     """Returns ``value`` if ``value`` is not ``None``. Returns ``replace_value`` otherwise.
#     """
#     if value is None:
#         return replace_value
#     else:
#         return value
# 
# Path: core/model/date.py
# def parse_date(string, format):
#     """Parses ``string`` into a ``datetime.date`` using ``format`` (ISO).
# 
#     .. seealso:: :class:`DateFormat`
#     """
#     return DateFormat(format).parse_date(string)
# 
# def format_date(date, format):
#     """Formats ``date`` using ``format`` (ISO).
# 
#     .. seealso:: :class:`DateFormat`
#     """
#     return format_year_month_day(date.year, date.month, date.day, format)


# Path: core/app.py
import os
import os.path as op
from core.util import nonone
from .gui.date_widget import DateWidget
from .model import currency
from .model._ccore import amount_configure
from .model.currency import Currencies
from .model.currency_provider import get_providers
from .model.date import parse_date, format_date

            if not op.exists(cache_path):
                os.makedirs(cache_path)
            db_path = op.join(cache_path, 'currency.db')
        else:
            db_path = ':memory:'
        currency.initialize_db(db_path)
        self._default_currency = default_currency
        self._date_format = date_format
        amount_configure(decimal_sep, grouping_sep)
        self._autosave_interval = self.get_default(PreferenceNames.AutoSaveInterval, 10)
        self._auto_decimal_place = self.get_default(PreferenceNames.AutoDecimalPlace, False)
        self._day_first_date_entry = self.get_default(PreferenceNames.DayFirstDateEntry, True)
        self._show_schedule_scope_dialog = self.get_default(PreferenceNames.ShowScheduleScopeDialog, True)
        self._hook_currency_providers()
        self._update_date_entry_order()

    # --- Private
    def _update_date_entry_order(self):
        DateWidget.setDMYEntryOrder(self._day_first_date_entry)

    def _hook_currency_providers(self):
        for p in get_providers():
            Currencies.get_rates_db().register_rate_provider(p().wrapped_get_currency_rates)

    # --- Public
    def format_date(self, date):
        """Returns a formatted date using app-wide preferences.

        This simply wraps :func:`core.model.date.format_date` and adds default values.
        """

        return format_date(date, self._date_format)