tirkarthi commented on code in PR #49914:
URL: https://github.com/apache/airflow/pull/49914#discussion_r2066211432
##########
airflow-core/src/airflow/ui/src/utils/datetimeUtils.ts:
##########
@@ -17,9 +17,36 @@
* under the License.
*/
import dayjs from "dayjs";
+import dayjsDuration from "dayjs/plugin/duration";
-export const getDuration = (startDate: string | null, endDate: string | null)
=>
- dayjs
- .duration(dayjs(endDate ?? undefined).diff(startDate ?? undefined))
- .asSeconds()
- .toFixed(2);
+dayjs.extend(dayjsDuration);
+
+export const getDuration = (startDate?: string | null, endDate?: string |
null) => {
+ const segments = [];
+
+ const seconds = dayjs.duration(dayjs(endDate ?? undefined).diff(startDate ??
undefined)).asSeconds();
+
+ if (seconds < 10) {
+ return `${seconds.toFixed(2)}s`;
+ }
+
+ const day = Math.floor(seconds / 60 / 60 / 24);
Review Comment:
dayjs offers formatting seconds to required format. Perhaps this logic could
be simplified as below to utilize this.
Ref : https://stackoverflow.com/a/71004873/2610955
```js
if (seconds < 86400) {
return dayjs.duration(seconds, "seconds").format('HH:mm:ss');
} else {
return dayjs.duration(seconds, "seconds").format('D[d]HH:mm:ss');
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]