我有一些看起来像这样的json....
[
{
"start": "20200629T202456Z",
"end": "20200629T211459Z",
"tags": [
"WPP",
"WPP review tasks, splashify popup",
"clients",
"work"
],
"annotation": "update rules, fix drush errors, create base wpp-splash module."
},
{
"start": "20200629T223000Z",
"end": "20200629T224641Z",
"tags": [
"WPP",
"WPP review tasks, splashify popup",
"clients",
"work"
]
},
]
我想显示小时:分钟的持续时间,而不是"开始"和"结束"时间。
时间格式可能有点不寻常(?(,它来自时间战士。 我想如果日期/时间存储在正常的 unix 时间戳中,jq
会更容易完成,但也许这仍然是可能的? jq可以像这样写入输出吗
[
{
"time": "0:50:03",
"tags": [
"WPP",
"WPP review tasks, splashify popup",
"clients",
"work"
],
"annotation": "update rules, fix drush errors, create base wpp-splash module."
}
]
或类似的东西。
这可能吗?
为了清楚起见,让我们定义一个帮助程序函数:
def duration($finish; $start):
def twodigits: "00" + tostring | .[-2:];
[$finish, $start]
| map(strptime("%Y%m%dT%H%M%SZ") | mktime) # seconds
| .[0] - .[1]
| (. % 60 | twodigits) as $s
| (((. / 60) % 60) | twodigits) as $m
| (./3600 | floor) as $h
| "($h):($m):($s)" ;
现在的解决方案很简单:
map( {time: duration(.end;.start)} + del(.start,.end) )