Skip to content

Commit

Permalink
testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaellinaresxk committed Sep 4, 2023
1 parent 2d9bc58 commit 946605b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
24 changes: 15 additions & 9 deletions src/components/topbar/StatusAlerts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
class="text-left text-caption d-flex flex-row alert-date text--secondary mt-0 mt-2"
:data-testid="`alert-date-${index}`"
>
{{ $t("common.labels.updateAt") }}
{{ getDate(item.timestamp) }} |
<template v-if="getUpdateDate(item.timestamp, item.createdAt)">
{{ $t("common.labels.updateAt") }}
{{ getUpdateDate(item.timestamp, item.createdAt) }} |
</template>
{{ $t("common.labels.createAt") }}
{{ getCreatedDate(item.createdAt) }}
{{ getCreationDate(item.createdAt) }}
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
Expand All @@ -46,7 +48,7 @@

<script lang="ts">
import { defineComponent, PropType } from "vue";
import { printDateTime, fromNow } from "../../plugins/datetime";
import { fromNow } from "../../plugins/datetime";
import { mdiAlertCircle, mdiInformation } from "@mdi/js";
import { StatusAlert } from "@/store/types/status-alert";
Expand All @@ -65,14 +67,18 @@ export default defineComponent({
: { icon: mdiInformation, color: "info" };
};
const getDate = (date: string) => {
return fromNow(date, true);
const getUpdateDate = (updateTime: string, creationTime: string) => {
if (updateTime && updateTime !== creationTime) {
return fromNow(updateTime); // Solo devuelve la fecha si hay una actualización
}
return ""; // Devuelve una cadena vacía si no hay fecha de actualización
};
const getCreatedDate = (dateTime: string) => {
return printDateTime(dateTime);
const getCreationDate = (creationTime: string) => {
return fromNow(creationTime); // Solo devuelve la fecha de creación
};
return { getIconTag, getDate, getCreatedDate };
return { getIconTag, getCreationDate, getUpdateDate };
},
});
</script>
Expand Down
32 changes: 27 additions & 5 deletions src/plugins/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,39 @@ export const createInputDateTime = (date) => {
];
};

function getPlural(value, singular, plural) {
return value === 1 ? singular : plural;
}

function determineTimeFormat(time, referenceTime) {
const minutesDiff = referenceTime.diff(dayjs(time), "minute");
const hoursDiff = referenceTime.diff(dayjs(time), "hour");
const daysDiff = referenceTime.diff(dayjs(time), "day");

if (minutesDiff < 60) {
return `${minutesDiff} ${getPlural(minutesDiff, "minute", "minutes")} ago`;
} else if (hoursDiff < 24) {
return `${hoursDiff} ${getPlural(hoursDiff, "hour", "hours")} ago`;
} else if (daysDiff < 7) {
return `${daysDiff} ${getPlural(daysDiff, "day", "days")} ago`;
} else {
return dayjs(time).format("DD.MM.YYYY");
}
}

/**
* Returns date difference to current local time
* @param {String} date
* @param {boolean} isLocalTimeZone set true if input date is to be handled in local time zone instead of utc
* @return {String} Date difference based on current timezone
*/
export const fromNow = (date, isLocalTimeZone) => {
if (isLocalTimeZone == true) {
return dayjs(date).fromNow();
}
return fromUTC(date).fromNow();

export const fromNow = (date, isLocalTimeZone = false) => {
// eslint-disable-next-line no-undef
return determineTimeFormat(
isLocalTimeZone ? dayjs(date) : dayjs.tz(date, "UTC"),
dayjs.tz()
);
};

/**
Expand Down

0 comments on commit 946605b

Please sign in to comment.