本文整理汇总了Python中arrow.Arrow.date方法的典型用法代码示例。如果您正苦于以下问题:Python Arrow.date方法的具体用法?Python Arrow.date怎么用?Python Arrow.date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arrow.Arrow
的用法示例。
在下文中一共展示了Arrow.date方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: time_ago
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import date [as 别名]
def time_ago(time_in: Arrow) -> str:
""" returns string saying how long ago the time on input was
"""
now = arrow.utcnow()
diff = now - time_in
sec_diff = int(diff.total_seconds())
rules = [
# threshold in seconds, view function, suffix
(120, lambda x: "", "<2 minutes"),
(7200, lambda x: int(x / 60), "minutes"),
(172800, lambda x: int(x / 3600), "hours"),
(5184000, lambda x: int(x / 86400), "days"),
# we should provide timezone # but it doesn't really matter here
(None, lambda x: time_in.date().isoformat(), ""),
]
for threshold, func, suffix in rules:
if threshold is None or sec_diff < threshold:
return "{} {}".format(func(sec_diff), suffix)
else:
raise RuntimeError("Unexpected error in time_ago filter,")