Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Valexr committed Apr 27, 2024
1 parent 60a9a4c commit 6c1ef12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
39 changes: 7 additions & 32 deletions src/lib/counters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@ export const counters = derived<[Writable<StartDate[]>, Writable<Quote[]>], Coun
set($dates.map(({ start, title, quote }, id) => count(id, start, title, quote)))

function count(id: number, start: string, title: string, quote: Quote) {
// const now = new Date();
// const start = new Date(date);
const elapsedMS = new Date().getTime() - new Date(start).getTime();
// const elapsedMonth = now.getMonth() - start.getMonth();
// const elapsedDays = now.getDate() - start.getDate();
// const daysInMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0,).getDate();
const years = new Date(elapsedMS).getFullYear() - 1970
const months = new Date(elapsedMS).getMonth()
const days = new Date(elapsedMS).getDate() - 1
// const months = (years * 12 + elapsedMonth) % 12
// const days = (months * daysInMonth + elapsedDays) % daysInMonth
const mss = new Date().getTime() - new Date(start).getTime();
const years = new Date(mss).getFullYear() - 1970
const months = new Date(mss).getMonth()
const days = new Date(mss).getDate() - 1
const weeks = Math.floor(days / 7)

return {
Expand All @@ -32,29 +25,11 @@ export const counters = derived<[Writable<StartDate[]>, Writable<Quote[]>], Coun
weeks: weeks,
full: {
months: years * 12 + months,
weeks: Math.trunc(elapsedMS / (3600000 * 24 * 7)),
days: Math.trunc(elapsedMS / (3600000 * 24)),
hours: Math.trunc(elapsedMS / 3600000)
weeks: Math.trunc(mss / (3600000 * 24 * 7)),
days: Math.trunc(mss / (3600000 * 24)),
hours: Math.trunc(mss / 3600000)
}
}
}
}, [])


Date.prototype.getElapsedTime = function () {
const diffDate = new Date(Date.now() - Number(this));
return (
"Elapsed Time: Years: " +
(diffDate.getFullYear() - 1970) +
", Months: " +
diffDate.getMonth() +
", Days: " +
(diffDate.getDate() - 1) +
", Hours: " +
diffDate.getHours() +
", Minutes: " +
diffDate.getMinutes() +
", Seconds: " +
diffDate.getSeconds()
);
};
20 changes: 19 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,22 @@ export function convert(en: keyof Translate, count = 0) {
function openDatepicker(input: HTMLInputElement) {
input.focus();
input.showPicker();
}
}

Date.prototype.getElapsedTime = function () {
const diffDate = new Date(Date.now() - Number(this));
return (
"Elapsed Time: Years: " +
(diffDate.getFullYear() - 1970) +
", Months: " +
diffDate.getMonth() +
", Days: " +
(diffDate.getDate() - 1) +
", Hours: " +
diffDate.getHours() +
", Minutes: " +
diffDate.getMinutes() +
", Seconds: " +
diffDate.getSeconds()
);
};

0 comments on commit 6c1ef12

Please sign in to comment.