Skip to content

Commit

Permalink
fix(ui): dynamic format date
Browse files Browse the repository at this point in the history
close #7015
  • Loading branch information
Skraye committed Jan 29, 2025
1 parent c180751 commit acdb46c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import {useRoute} from "vue-router";
import {Utils} from "@kestra-io/ui-libs";
import KestraUtils from "../../../../../utils/utils.js"
const store = useStore();
Expand Down Expand Up @@ -129,7 +130,7 @@
const parsedData = computed(() => {
const parseValue = (value) => {
const date = moment(value, moment.ISO_8601, true);
return date.isValid() ? date.format("YYYY-MM-DD") : value;
return date.isValid() ? date.format(KestraUtils.getDateFormat(route.query.startDate, route.query.endDate)) : value;
};
const rawData = generated.value.results;
Expand Down
20 changes: 20 additions & 0 deletions ui/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,24 @@ export default class Utils {
}
return obj;
}

static getDateFormat(startDate, endDate) {
if (!startDate || !endDate) {
return "yyyy-MM-DD";
}

const duration = moment.duration(moment(endDate).diff(moment(startDate)));

if (duration.asDays() > 365) {
return "yyyy-MM";
} else if (duration.asDays() > 180) {
return "yyyy-'W'ww";
} else if (duration.asDays() > 1) {
return "yyyy-MM-DD";
} else if (duration.asHours() > 1) {
return "yyyy-MM-DD:HH:00";
} else {
return "yyyy-MM-DD:HH:mm";
}
}
}

0 comments on commit acdb46c

Please sign in to comment.