人类日期时间与 Pendulum 的差异
Human datetime diffs with Pendulum
我最近偶然发现了这个很棒的 pendulum
"datetimes made easy" 库。
它有一个非常好的功能,可以显示 "human like" 日期时间之间的差异:
In [1]: import pendulum
In [2]: now = pendulum.now()
In [3]: future = now.add(years=10)
In [4]: future.diff_for_humans()
Out[4]: '10 years from now'
但是,是否有可能使其适用于更复杂的差异 - 例如 "years" 和 "weeks"?
In [5]: future = now.add(years=10, weeks=5)
In [6]: future.diff_for_humans()
Out[6]: '10 years from now'
我希望它输出 10 years and 5 weeks from now
。
来自 Pendulum 模块自述文件:
now = pendulum.now()
future = now.add(years=10, weeks=5)
delta = future - now
delta.in_words()
>>>'10 years 1 month 4 days'
我最近偶然发现了这个很棒的 pendulum
"datetimes made easy" 库。
它有一个非常好的功能,可以显示 "human like" 日期时间之间的差异:
In [1]: import pendulum
In [2]: now = pendulum.now()
In [3]: future = now.add(years=10)
In [4]: future.diff_for_humans()
Out[4]: '10 years from now'
但是,是否有可能使其适用于更复杂的差异 - 例如 "years" 和 "weeks"?
In [5]: future = now.add(years=10, weeks=5)
In [6]: future.diff_for_humans()
Out[6]: '10 years from now'
我希望它输出 10 years and 5 weeks from now
。
来自 Pendulum 模块自述文件:
now = pendulum.now()
future = now.add(years=10, weeks=5)
delta = future - now
delta.in_words()
>>>'10 years 1 month 4 days'