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))
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
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
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)))
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()
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
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
def since(self): return timesince( self.action["mtime"], locale=self.locale)
def since(self): return timesince(self.action["mtime"])
def time_since(timestamp): return (timesince(timestamp, locale=get_language()) if timestamp else "")
def do_relative_datetime_format(value): return timesince(calendar.timegm(value.timetuple()), locale=get_language())
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
def do_relative_datetime_format(value): return timesince( calendar.timegm(value.timetuple()), locale=get_language())
def time_since(timestamp): return ( timesince( timestamp, locale=get_language()) if timestamp else "")
def do_relative_datetime_format(value): return timesince(calendar.timegm(value.timetuple()))
def since(self): return timesince(self.action["mtime"], locale=self.locale)