added usePersianTimeAgo
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
// composables/usePersianTimeAgo.ts
|
||||||
|
import { ref, onMounted, onUnmounted } from "vue";
|
||||||
|
import { formatDistance, toDate } from "date-fns-jalali";
|
||||||
|
import { faIR } from "date-fns-jalali/locale";
|
||||||
|
|
||||||
|
export function usePersianTimeAgo(date: Date) {
|
||||||
|
const timeAgo = ref("");
|
||||||
|
|
||||||
|
const updateTimeAgo = () => {
|
||||||
|
timeAgo.value = formatDistance(toDate(date), new Date(), {
|
||||||
|
addSuffix: true,
|
||||||
|
locale: faIR,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
updateTimeAgo();
|
||||||
|
|
||||||
|
const interval = setInterval(updateTimeAgo, 60000);
|
||||||
|
|
||||||
|
onUnmounted(() => clearInterval(interval));
|
||||||
|
});
|
||||||
|
|
||||||
|
return timeAgo;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user