Example #1
0
def test_local_date_timesince(settings):
    timestamp = time.time() - 1000000
    timedelta = datetime.now() - datetime.fromtimestamp(timestamp)
    language = str(get_locale_formats().locale)
    assert timesince(timestamp) == format_timedelta(timedelta, locale=language)
    assert (timesince(timestamp,
                      locale="ff") == timesince(timestamp,
                                                locale=settings.LANGUAGE_CODE))
Example #2
0
 def child_update_times(self):
     _times = {}
     for child in self.children:
         if not child.get("stats"):
             continue
         last_created_unit = (
             timesince(child["stats"]["last_created_unit"]["creation_time"],
                       locale=self.view.request_lang)
             if child["stats"].get("last_created_unit") else None)
         last_submission = (timesince(
             child["stats"]["last_submission"]["mtime"],
             locale=self.view.request_lang) if
                            child["stats"].get("last_submission") else None)
         _times[child["code"]] = (last_submission, last_created_unit)
     return _times
Example #3
0
 def child_update_times(self):
     _times = {}
     for child in self.children:
         if not child.get("stats"):
             continue
         last_created_unit = (
             timesince(
                 child["stats"]["last_created_unit"]["creation_time"],
                 locale=self.view.request_lang)
             if child["stats"].get("last_created_unit")
             else None)
         last_submission = (
             timesince(
                 child["stats"]["last_submission"]["mtime"],
                 locale=self.view.request_lang)
             if child["stats"].get("last_submission")
             else None)
         _times[child["code"]] = (last_submission, last_created_unit)
     return _times
Example #4
0
def test_local_date_timesince(settings):
    timestamp = time.time() - 1000000
    assert (
        timesince(timestamp)
        == format_timedelta(
            datetime.now()
            - datetime.fromtimestamp(timestamp),
            locale=(
                localdate.locale_code
                or localdate.default_locale)))
Example #5
0
def test_model_user_last_event(member):
    last_submission = Submission.objects.filter(submitter=member).last()
    last_event = member.last_event()
    assert isinstance(last_event, ActionDisplay)
    assert last_event.action == last_submission.get_submission_info()

    last_event = member.last_event(locale="zu")
    assert isinstance(last_event, ActionDisplay)
    assert last_event.action == last_submission.get_submission_info()
    assert last_event.since == timesince(last_event.action["mtime"], "zu")
    user = UserFactory()
    assert not user.last_event()
Example #6
0
 def get_entries_group_data(self, context):
     result = []
     for entry_group in context['entries_group']:
         display_dt = entry_group['datetime']
         if display_dt is not None:
             display_dt = dateformat.format(display_dt)
             iso_dt = entry_group['datetime'].isoformat()
             relative_time = timesince(
                 calendar.timegm(entry_group['datetime'].timetuple()))
         else:
             iso_dt = None
             relative_time = None
         result.append({
             "display_datetime": display_dt,
             "iso_datetime": iso_dt,
             "relative_time": relative_time,
             "via_upload": entry_group.get('via_upload', False),
         })
     return result
Example #7
0
 def get_event_groups_data(self, context):
     result = []
     for event_group in context['event_groups']:
         display_dt = event_group['datetime']
         if display_dt is not None:
             display_dt = dateformat.format(display_dt)
             iso_dt = event_group['datetime'].isoformat()
             relative_time = timesince(
                 calendar.timegm(event_group['datetime'].timetuple()),
                 self.request_lang)
         else:
             iso_dt = None
             relative_time = None
         result.append({
             "display_datetime": display_dt,
             "iso_datetime": iso_dt,
             "relative_time": relative_time,
             "via_upload": event_group.get('via_upload', False),
         })
     return result
Example #8
0
 def since(self):
     return timesince(
         self.action["mtime"],
         locale=self.locale)
Example #9
0
 def since(self):
     return timesince(self.action["mtime"])
Example #10
0
def time_since(timestamp):
    return (timesince(timestamp, locale=get_language()) if timestamp else "")
Example #11
0
def do_relative_datetime_format(value):
    return timesince(calendar.timegm(value.timetuple()), locale=get_language())
Example #12
0
def test_local_date_timesince_wrong_locale(language, fallback):
    timestamp = time.time() - 1000000
    timedelta = datetime.now() - datetime.fromtimestamp(timestamp)
    fallback_format = get_locale_formats(fallback)
    fallback_timedelta = fallback_format.timedelta(timedelta, format='long')
    assert timesince(timestamp, locale=language) == fallback_timedelta
Example #13
0
def do_relative_datetime_format(value):
    return timesince(
        calendar.timegm(value.timetuple()),
        locale=get_language())
Example #14
0
def time_since(timestamp):
    return (
        timesince(
            timestamp, locale=get_language())
        if timestamp
        else "")
Example #15
0
def do_relative_datetime_format(value):
    return timesince(calendar.timegm(value.timetuple()))
Example #16
0
 def since(self):
     return timesince(self.action["mtime"], locale=self.locale)