gpt4 book ai didi

javascript - 将单词秒转换为周、天、小时和分钟

转载 作者:行者123 更新时间:2023-11-29 23:47:05 25 4
gpt4 key购买 nike

我正在使用 jira rest api 来解决问题。问题估计时间以秒数返回 - 但基于每周 5 天,每天 8 小时。

因此,例如,1d 的估计时间返回为 28800 秒

我有这段代码可以做我想做的事,但它闻起来很臭,我想知道是否有更好的函数来做我想做的事

 let es = 246180; // time (number of *work* seconds) is "1w 3d 4h 23m"
let sInMin = 60;
let sInHour = (60 * 60);
let sInDay = (sInHour * 8);
let sInWeek = (sInDay * 5);

let w = Math.trunc(es / sInWeek);
let d = Math.trunc((es - (w * sInWeek)) / sInDay);
let h = Math.trunc((es - (w * sInWeek) - (d * sInDay)) / sInHour);
let m = Math.trunc((es - (w * sInWeek) - (d * sInDay) - (h * sInHour)) / sInMin);

console.log(w,d,h,m) // 1 3 4 23

如果我将 momentmoment-duration-format 添加到组合中,我就可以做

moment.duration({w,d,h,m}).format("w[w] d[d] h[h] m[m]")

得到神奇的1w 3d 4h 23m字符串

我该如何改进?

最佳答案

JIRA REST API 已经为您提供了您要计算的字段。

来自他们文档中的示例响应 here :

"timetracking": {
"originalEstimate": "10m",
"remainingEstimate": "3m",
"timeSpent": "6m",
"originalEstimateSeconds": 600,
"remainingEstimateSeconds": 200,
"timeSpentSeconds": 400
}

您正在获取 originalEstimateSeconds 字段并尝试进行数学运算以获取字符串,但该字符串已经在 originalEstimate 字段中为您生成。无需计算。

关于javascript - 将单词秒转换为周、天、小时和分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43618832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com