refactor: move function to utile

This commit is contained in:
Thanaphon Frappet 2024-10-25 16:33:49 +07:00
parent 1a2d5ed502
commit 03d0916f26
2 changed files with 11 additions and 9 deletions

View file

@ -1,16 +1,9 @@
<script lang="ts" setup>
import { calculateDaysUntilExpire } from 'stores/utils';
defineProps<{
expirationDate: Date;
}>();
function calculateDaysUntilExpire(expireDate: Date): number {
const today = new Date();
const expire = new Date(expireDate);
const diffInTime = expire.getTime() - today.getTime();
const diffInDays = Math.ceil(diffInTime / (1000 * 60 * 60 * 24));
return diffInDays;
}
</script>
<template>

View file

@ -495,4 +495,13 @@ export async function getAttachmentHead(api: AxiosInstance, url: string) {
if (res) return res.headers;
}
export function calculateDaysUntilExpire(expireDate: Date): number {
const today = new Date();
const expire = new Date(expireDate);
const diffInTime = expire.getTime() - today.getTime();
const diffInDays = Math.ceil(diffInTime / (1000 * 60 * 60 * 24));
return diffInDays;
}
export default useUtilsStore;