本文整理汇总了Python中inc.Commons.Commons.format_time_delta方法的典型用法代码示例。如果您正苦于以下问题:Python Commons.format_time_delta方法的具体用法?Python Commons.format_time_delta怎么用?Python Commons.format_time_delta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inc.Commons.Commons
的用法示例。
在下文中一共展示了Commons.format_time_delta方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_format_time_delta
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import format_time_delta [as 别名]
def test_format_time_delta(self):
delta1 = timedelta(5, 5)
assert Commons.format_time_delta(delta1) == "P5T5S"
delta2 = timedelta(0, 50)
assert Commons.format_time_delta(delta2) == "P0T50S"
delta3 = timedelta(3, 0, 0, 0, 1)
assert Commons.format_time_delta(delta3) == "P3T60S"
delta4 = timedelta(2, 0, 0, 0, 0, 1)
assert Commons.format_time_delta(delta4) == "P2T3600S"
delta5 = timedelta(0, 0, 0, 0, 0, 0, 1)
assert Commons.format_time_delta(delta5) == "P7T0S"
示例2: to_xml_string
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import format_time_delta [as 别名]
def to_xml_string(self):
"""
Saves this E621 subscription
:rtype: str
"""
# Create root element
root = ElementTree.Element("e621_sub")
# Create search element
search = ElementTree.SubElement(root, "search")
search.text = self.search
# Create server name element
server = ElementTree.SubElement(root, "server")
server.text = self.server_name
# Create channel name element, if applicable
if self.channel_name is not None:
channel = ElementTree.SubElement(root, "channel")
channel.text = self.channel_name
# Create user name element, if applicable
if self.user_name is not None:
user = ElementTree.SubElement(root, "user")
user.text = self.user_name
# Create latest id elements
for latest_id in self.latest_ten_ids:
latest_id_elem = ElementTree.SubElement(root, "latest_id")
latest_id_elem.text = str(latest_id)
# Create last check element
if self.last_check is not None:
last_check = ElementTree.SubElement(root, "last_check")
last_check.text = self.last_check.isoformat()
# Create update frequency element
update_frequency = ElementTree.SubElement(root, "update_frequency")
update_frequency.text = Commons.format_time_delta(self.update_frequency)
# Return xml string
return ElementTree.tostring(root)
示例3: to_json
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import format_time_delta [as 别名]
def to_json(self):
"""
:rtype: dict
"""
json_obj = dict()
json_obj["server_name"] = self.server.name
if isinstance(self.destination, Channel):
json_obj["channel_address"] = self.destination.address
if isinstance(self.destination, User):
json_obj["user_address"] = self.destination.address
if self.last_check is not None:
json_obj["last_check"] = self.last_check.isoformat()
json_obj["update_frequency"] = Commons.format_time_delta(self.update_frequency)
if self.last_update is not None:
json_obj["last_update"] = self.last_update.isoformat()
return json_obj