Skip to content

Commit

Permalink
Merge f800a1b into a310008
Browse files Browse the repository at this point in the history
  • Loading branch information
iambibhas committed Jun 12, 2020
2 parents a310008 + f800a1b commit aeae260
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions baseframe/filters.py
Expand Up @@ -54,6 +54,7 @@ def age(dt):
else:
return _("%(num)s years ago", num=int(delta.days / 365))


@baseframe.app_template_filter('initials')
def initials(text):
"""
Expand Down Expand Up @@ -271,3 +272,15 @@ def datetime_filter(value, format='medium', locale=None, usertz=True): # NOQA:
return format_datetime(
dt, format=format, locale=locale if locale else get_locale()
) # NOQA: A002


@baseframe.app_template_filter('timestamp')
def timestamp_filter(value):
if isinstance(value, datetime):
if six.PY2:
ts = (value - datetime(1970, 1, 1)).total_seconds()
else:
ts = value.timestamp()
else:
ts = value
return ts
4 changes: 4 additions & 0 deletions tests/test_filters.py
Expand Up @@ -186,6 +186,10 @@ def test_date_mdy(self):
== '1/31/20'
)

def test_timestamp(self):
with self.app.test_request_context('/'):
assert filters.timestamp_filter(self.datetime) == 1580428800.0


class TestNaiveDatetimeFilters(TestDatetimeFilters):
def setUp(self):
Expand Down

0 comments on commit aeae260

Please sign in to comment.