def iso8601_to_rostime(iso):
"""Converts ISO 8601 time to ROS Time.
Args:
iso: ISO 8601 encoded string.
Returns:
std_msgs/Time.
"""
# Convert to datetime in UTC.
t = dateutil.parser.parse(iso)
if not t.utcoffset():
t = t.replace(tzinfo=tzutc())
# Convert to time from epoch in UTC.
epoch = datetime.utcfromtimestamp(0)
epoch = epoch.replace(tzinfo=tzutc())
dt = t - epoch
# Create ROS message.
time = Time()
time.data.secs = int(dt.total_seconds())
time.data.nsecs = dt.microseconds * 1000
return time
评论列表
文章目录