Skip to content

Commit

Permalink
Added functionality to update date format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaellinaresxk committed Sep 5, 2023
1 parent 946605b commit b502637
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/components/topbar/StatusAlerts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ export default defineComponent({
const getUpdateDate = (updateTime: string, creationTime: string) => {
if (updateTime && updateTime !== creationTime) {
return fromNow(updateTime); // Solo devuelve la fecha si hay una actualización
return fromNow(updateTime);
}
return ""; // Devuelve una cadena vacía si no hay fecha de actualización
return "";
};
const getCreationDate = (creationTime: string) => {
return fromNow(creationTime); // Solo devuelve la fecha de creación
return fromNow(creationTime);
};
return { getIconTag, getCreationDate, getUpdateDate };
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@ function getPlural(value, 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");
const secondsDiff = (referenceTime - time) / 1000; // Convert to seconds
const minutesDiff = Math.floor(secondsDiff / 60);
const hoursDiff = Math.floor(secondsDiff / 3600);
const daysDiff = Math.floor(secondsDiff / (24 * 3600));

if (minutesDiff < 60) {
return `${minutesDiff} ${getPlural(minutesDiff, "minute", "minutes")} ago`;
Expand All @@ -253,7 +254,7 @@ function determineTimeFormat(time, referenceTime) {
} else if (daysDiff < 7) {
return `${daysDiff} ${getPlural(daysDiff, "day", "days")} ago`;
} else {
return dayjs(time).format("DD.MM.YYYY");
return time.format("DD.MM.YYYY");
}
}

Expand Down

0 comments on commit b502637

Please sign in to comment.