我正在寻找一个Python(v2)库,它允许我解析和比较iso8601持续时间,这些持续时间可能以不同的单位表示
理想情况下,它可以与标准运算符(a<;b)一起工作,但我对a.compare(b)之类的东西很酷。在
比如说:
duration('P23M') < duration('P2Y') //True
duration('P25M') < duration('P2Y') //False
我已经从PyPi安装了isodate,但是它有自己的类来处理包括月份和年份在内的周期,它们不能与它们自己或与timedelta进行比较
Tags:
我最终“解决”这个问题的方法是比较结果值,如果将周期加到一个保持当前UTC时间的值上。这当然意味着,在2月份,P30D比P1M长,3月份短,4月份相等。不太理想,但很好地满足了我的需要。在
以下是一些关于持续时间的胡说八道(一个月是30天,一年是平均值,等等):
面对同样的问题,我求助于正则表达式来解析持续时间并比较得到的秒数:
注意,这隐含地假设一年是365天,一个月是30天,等等
相关问题 更多 >
编程相关推荐