Update time calculations in BannerComponent and TicketNormalizer

Refactored BannerComponent to use an imported date function, improved time calculation logic, and enhanced code readability. Also, updated TicketNormalizer to properly normalize various datetime and user-related fields. A new date validation check has been added in the date utility file.
This commit is contained in:
Julien Fastré 2024-06-01 00:31:39 +02:00
parent 498572b96e
commit ac4e2e5bf2
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 23 additions and 8 deletions

View File

@ -59,6 +59,10 @@ export const ISOToDatetime = (str: string|null): Date|null => {
[hours, minutes, seconds] = time.split(':').map(s => parseInt(s));
;
if ('0000' === timezone) {
return new Date(Date.UTC(year, month-1, date, hours, minutes, seconds));
}
return new Date(year, month-1, date, hours, minutes, seconds);
}

View File

@ -79,6 +79,7 @@ import AddresseeComponent from "./AddresseeComponent.vue";
// Types
import { Ticket } from "../../../types";
import {ISOToDatetime} from "../../../../../../../ChillMainBundle/Resources/public/chill/js/date";
export default defineComponent({
name: "BannerComponent",
@ -95,14 +96,21 @@ export default defineComponent({
setup(props) {
const { t } = useI18n();
const today = ref(new Date());
const createdAt = ref(props.ticket.createdAt as any);
const createdAt = ref(props.ticket.createdAt);
setInterval(function () {
today.value = new Date();
}, 1000);
}, 5000);
const since = computed(() => {
const date = new Date(createdAt.value.date);
if (null === createdAt.value) {
return "";
}
const date = ISOToDatetime(createdAt.value.datetime);
if (null === date) {
return "";
}
const timeDiff = Math.abs(today.value.getTime() - date.getTime());
const daysDiff = Math.floor(timeDiff / (1000 * 3600 * 24));
@ -115,11 +123,12 @@ export default defineComponent({
const secondsDiff = Math.floor((timeDiff % (1000 * 60)) / 1000);
if (daysDiff < 1 && hoursDiff < 1 && minutesDiff < 1) {
return `${t("banner.seconds", { count: secondsDiff })}`;
return `${t("banner.seconds", {count: secondsDiff})}`;
} else if (daysDiff < 1 && hoursDiff < 1) {
return `${t("banner.minutes", { count: minutesDiff })}`;
} else if (daysDiff < 1) {
return `${t("banner.hours", { count: hoursDiff })}
${t("banner.minutes", { count: minutesDiff })}
${t("banner.seconds", { count: secondsDiff })}`;
${t("banner.minutes", { count: minutesDiff })}`;
} else {
return `${t("banner.days", { count: daysDiff })}, ${t(
"banner.hours",

View File

@ -44,8 +44,10 @@ final class TicketNormalizer implements NormalizerInterface, NormalizerAwareInte
'currentInputs' => $this->normalizer->normalize($object->getCurrentInputs(), $format, ['groups' => 'read']),
'currentMotive' => $this->normalizer->normalize($object->getMotive(), $format, ['groups' => 'read']),
'history' => array_values($this->serializeHistory($object, $format, ['groups' => 'read'])),
'createdAt' => $object->getCreatedAt(),
'updatedBy' => $object->getUpdatedBy(),
'createdAt' => $this->normalizer->normalize($object->getCreatedAt(), $format, $context),
'updatedAt' => $this->normalizer->normalize($object->getUpdatedAt(), $format, $context),
'updatedBy' => $this->normalizer->normalize($object->getUpdatedBy(), $format, $context),
'createdBy' => $this->normalizer->normalize($object->getCreatedBy(), $format, $context),
];
}