import datetime
from bisect import insort

from vistas.core.utils import DatetimeEncoder, DatetimeDecoder
from vistas.ui.events import TimelineEvent
from vistas.ui.utils import post_timeline_change


class Timeline:
    _global_timeline = None

    @classmethod
    def app(cls):
        """ Global timeline """

        if cls._global_timeline is None:
            cls._global_timeline = Timeline()

        return cls._global_timeline

    def __init__(self, start=None, end=None, current=None):

        init_time = datetime.datetime.fromtimestamp(0)

        self._start = init_time if start is None else start
        self._end = init_time if end is None else end
        self._current = init_time if current is None else current