Created
May 13, 2013 03:02
-
-
Save aoshiman/5565918 to your computer and use it in GitHub Desktop.
timesince filter(http://flask.pocoo.org/snippets/33/)を日本語ローカライズしflashに対応させたもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from datetime import datetime | |
def timesince(dt, default=u"記事が投稿されました"): | |
""" | |
timesince filter | |
http://flask.pocoo.org/snippets/33/ | |
を日本語ローカライズしflashに対応させたもの | |
""" | |
now = datetime.now() | |
diff = now - dt | |
periods = ( | |
(diff.days / 365, u"年"), | |
(diff.days / 30, u"ヶ月"), | |
(diff.days / 7, u"週間"), | |
(diff.days, u"日"), | |
(diff.seconds / 3600, u"時間"), | |
(diff.seconds / 60, u"分"), | |
(diff.seconds, u"秒"), | |
) | |
for period, unit in periods: | |
if period: | |
return u"この記事は投稿から %d %s が経過しています" % (period, unit) | |
return default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment