Esempio n. 1
0
 def test_today(self):
     with freeze_time('2016-9-19 8:00'):
         today13 = dt.datetime.combine(dt.date.today(), dt.time(13, 0))
         assert (today13, False) == guessdatetimefstr(['today', '13:00'],
                                                      LOCALE_BERLIN)
         assert dt.date.today() == guessdatetimefstr(
             ['today'], LOCALE_BERLIN)[0].date()
Esempio n. 2
0
 def test_long_not_configured(self):
     """long version is not configured, but short contains the year"""
     locale = {
         'timeformat': '%H:%M',
         'dateformat': '%Y-%m-%d',
         'longdateformat': '',
         'datetimeformat': '%Y-%m-%d %H:%M',
         'longdatetimeformat': '',
     }
     assert (dt.datetime(2017, 1, 1), True) == guessdatetimefstr(
         '2017-1-1'.split(), locale=locale, default_day=dt.datetime.today())
     assert (dt.datetime(2017, 1, 1, 16, 30), False) == guessdatetimefstr(
         '2017-1-1 16:30'.split(), locale=locale, default_day=dt.datetime.today())
Esempio n. 3
0
 def test_long_not_configured(self):
     """long version is not configured, but short contains the year"""
     locale = {
         'timeformat': '%H:%M',
         'dateformat': '%Y-%m-%d',
         'longdateformat': '',
         'datetimeformat': '%Y-%m-%d %H:%M',
         'longdatetimeformat': '',
     }
     assert (dt.datetime(2017, 1, 1), True) == guessdatetimefstr(
         '2017-1-1'.split(), locale=locale, default_day=dt.datetime.today())
     assert (dt.datetime(2017, 1, 1, 16, 30), False) == guessdatetimefstr(
         '2017-1-1 16:30'.split(), locale=locale, default_day=dt.datetime.today())
Esempio n. 4
0
 def test_short_format_contains_year(self):
     """if the non long versions of date(time)format contained a year, the
     current year would be used instead of the given one, see #545"""
     locale = {
         'timeformat': '%H:%M',
         'dateformat': '%Y-%m-%d',
         'longdateformat': '%Y-%m-%d',
         'datetimeformat': '%Y-%m-%d %H:%M',
         'longdatetimeformat': '%Y-%m-%d %H:%M',
     }
     assert (dt.datetime(2017, 1, 1), True) == guessdatetimefstr(
         '2017-1-1'.split(), locale=locale, default_day=dt.datetime.today())
     assert (dt.datetime(2017, 1, 1, 16, 30), False) == guessdatetimefstr(
         '2017-1-1 16:30'.split(), locale=locale, default_day=dt.datetime.today())
Esempio n. 5
0
 def test_short_format_contains_year(self):
     """if the non long versions of date(time)format contained a year, the
     current year would be used instead of the given one, see #545"""
     locale = {
         'timeformat': '%H:%M',
         'dateformat': '%Y-%m-%d',
         'longdateformat': '%Y-%m-%d',
         'datetimeformat': '%Y-%m-%d %H:%M',
         'longdatetimeformat': '%Y-%m-%d %H:%M',
     }
     assert (dt.datetime(2017, 1, 1), True) == guessdatetimefstr(
         '2017-1-1'.split(), locale=locale, default_day=dt.datetime.today())
     assert (dt.datetime(2017, 1, 1, 16, 30), False) == guessdatetimefstr(
         '2017-1-1 16:30'.split(), locale=locale, default_day=dt.datetime.today())
Esempio n. 6
0
 def test_time_weekday(self):
     with freeze_time('2016-9-19'):
         assert (dt.datetime(2016, 9, 23, 16), False) == \
             guessdatetimefstr(
                 'Friday 16:00'.split(),
                 locale=LOCALE_BERLIN,
                 default_day=dt.datetime.today())
Esempio n. 7
0
 def test_today(self):
     assert (dt.datetime(2016, 9, 19, 13), False) == \
         guessdatetimefstr(['today', '13:00'], LOCALE_BERLIN)
     assert dt.date.today() == guessdatetimefstr(['today'],
                                                 LOCALE_BERLIN)[0].date()
Esempio n. 8
0
def khal_list(collection,
              daterange=None,
              conf=None,
              agenda_format=None,
              day_format=None,
              once=False,
              notstarted=False,
              width=False,
              env=None,
              datepoint=None):
    assert daterange is not None or datepoint is not None
    """returns a list of all events in `daterange`"""
    # because empty strings are also Falsish
    if agenda_format is None:
        agenda_format = conf['view']['agenda_event_format']

    if daterange is not None:
        if day_format is None:
            day_format = conf['view']['agenda_day_format']
        start, end = start_end_from_daterange(
            daterange,
            conf['locale'],
            default_timedelta_date=conf['default']['timedelta'],
            default_timedelta_datetime=conf['default']['timedelta'],
        )
        logger.debug('Getting all events between {} and {}'.format(start, end))

    elif datepoint is not None:
        if not datepoint:
            datepoint = ['now']
        try:
            start, allday = parse_datetime.guessdatetimefstr(
                datepoint,
                conf['locale'],
                dt.date.today(),
            )
        except ValueError:
            raise FatalError('Invalid value of `{}` for a datetime'.format(
                ' '.join(datepoint)))
        if allday:
            logger.debug('Got date {}'.format(start))
            raise FatalError('Please supply a datetime, not a date.')
        end = start + dt.timedelta(seconds=1)
        if day_format is None:
            day_format = style(
                start.strftime(conf['locale']['longdatetimeformat']),
                bold=True,
            )
        logger.debug('Getting all events between {} and {}'.format(start, end))

    event_column = []
    once = set() if once else None
    if env is None:
        env = {}

    original_start = conf['locale']['local_timezone'].localize(start)
    while start < end:
        if start.date() == end.date():
            day_end = end
        else:
            day_end = dt.datetime.combine(start.date(), dt.time.max)
        current_events = get_events_between(
            collection,
            locale=conf['locale'],
            agenda_format=agenda_format,
            start=start,
            end=day_end,
            notstarted=notstarted,
            original_start=original_start,
            env=env,
            seen=once,
            width=width,
        )
        if day_format and (conf['default']['show_all_days'] or current_events):
            event_column.append(
                format_day(start.date(), day_format, conf['locale']))
        event_column.extend(current_events)
        start = dt.datetime(*start.date().timetuple()[:3]) + dt.timedelta(
            days=1)

    if event_column == []:
        event_column = [style('No events', bold=True)]
    return event_column
Esempio n. 9
0
def get_summary(collection, conf, locale, dates=None, firstweekday=0, days=None, events=None, width=45,
               week=False, full=False, show_all_days=False, bold_for_light_color=True,):
    """returns a list of events scheduled for all days in daylist

    included are header "rows"
    :param collection:
    :type collection: khalendar.CalendarCollection
    :param dates: a list of all dates for which the events should be return,
                    including what should be printed as a header
    :type collection: list(str)
    :param show_all_days: True if all days must be shown, event without event
    :type show_all_days: Boolean
    :returns: a list to be printed as the agenda for the given days
    :rtype: list(str)

    """
    from datetime import date, timedelta
    from click import style, echo

    event_column = list()

    if days is None:
        days = 2

    if dates is None or len(dates) == 0:
        dates = [date.today()]
    else:
        try:
            dates = [
                guessdatetimefstr([day], locale)[0].date()
                if not isinstance(day, date) else day
                for day in dates
            ]
        except InvalidDate as error:
            logging.fatal(error)
            sys.exit(1)

    if week:
        dates = [d - timedelta((d.weekday() - firstweekday) % 7)
                 for d in dates]
        days = 7

    if days is not None:
        daylist = [day + timedelta(days=one)
                   for one in range(days) for day in dates]
        daylist.sort()

    last_day = None
    for day in daylist:
        if last_day is None or day.month != last_day.month:
            event_column.append(style(day.strftime("%B"), bold=True))

        last_day = day
        events = sorted(collection.get_events_on(day))
        if is_holiday(day):
            prefix = style(day.strftime("%d*%a: "), bold=True)
        else:
            prefix = style(day.strftime("%d %a: "), bold=False)
        if not events:
            event_column.append(prefix)
            continue
        for event in events:
            lines = list()
            items = event.format(conf['view']['agenda_event_format'], day).splitlines()
            for item in items:
                lines += textwrap.wrap(item, width)
            lines = [colored(line, event.color, bold_for_light_color=bold_for_light_color) for line in lines]
            event_column.append(prefix + lines[0])
            prefix = " " * 8
            event_column += [prefix + line for line in lines[1:]]

    if event_column == []:
        event_column = [style('No events', bold=True)]
    return event_column
Esempio n. 10
0
 def test_tomorrow(self):
     assert (dt.datetime(2016, 9, 20, 16), False) == \
         guessdatetimefstr('tomorrow 16:00 16:00'.split(), locale=LOCALE_BERLIN)
Esempio n. 11
0
 def test_time_yesterday(self):
     assert (dt.datetime(2016, 9, 18, 16),
             False) == guessdatetimefstr('Yesterday 16:00'.split(),
                                         locale=LOCALE_BERLIN,
                                         default_day=dt.datetime.today())
Esempio n. 12
0
 def test_time_tomorrow(self):
     assert (self.tomorrow16, False) == \
         guessdatetimefstr('16:00'.split(), locale=LOCALE_BERLIN, default_day=tomorrow)
Esempio n. 13
0
 def test_time_now(self):
     assert (dt.datetime(2016, 9, 19, 17, 53), False) == guessdatetimefstr(
         'now'.split(), locale=LOCALE_BERLIN, default_day=dt.datetime.today())
Esempio n. 14
0
 def test_time_weekday(self):
     assert (dt.datetime(2016, 9, 23, 16), False) == guessdatetimefstr(
         'Friday 16:00'.split(),
         locale=LOCALE_BERLIN,
         default_day=dt.datetime.today())
Esempio n. 15
0
 def test_time_tomorrow(self):
     assert (dt.datetime(2016, 9, 20, 16), False) == \
         guessdatetimefstr(
             '16:00'.split(), locale=LOCALE_BERLIN, default_day=dt.date(2016, 9, 20))
Esempio n. 16
0
 def test_tomorrow(self):
     assert (dt.datetime(2016, 9, 20, 16), False) == \
         guessdatetimefstr('tomorrow 16:00 16:00'.split(), locale=LOCALE_BERLIN)
Esempio n. 17
0
 def test_time_tomorrow(self):
     assert (dt.datetime(2016, 9, 20, 16), False) == \
         guessdatetimefstr(
             '16:00'.split(), locale=LOCALE_BERLIN, default_day=dt.date(2016, 9, 20))
Esempio n. 18
0
 def test_time_now(self):
     with freeze_time('2016-9-19 17:53'):
         assert (dt.datetime(2016, 9, 19, 17, 53), False) == \
             guessdatetimefstr(
                 'now'.split(), locale=LOCALE_BERLIN, default_day=dt.datetime.today(),
             )
Esempio n. 19
0
 def test_time_now(self):
     assert (dt.datetime(2016, 9, 19, 17, 53),
             False) == guessdatetimefstr('now'.split(),
                                         locale=LOCALE_BERLIN,
                                         default_day=dt.datetime.today())
Esempio n. 20
0
 def test_today(self):
     assert (dt.datetime(2016, 9, 19, 13), False) == \
         guessdatetimefstr(['today', '13:00'], LOCALE_BERLIN)
     assert dt.date.today() == guessdatetimefstr(['today'], LOCALE_BERLIN)[0].date()