Skip to content

Commit

Permalink
fix counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Valexr committed Apr 14, 2024
1 parent f3052e2 commit 9922772
Showing 1 changed file with 28 additions and 67 deletions.
95 changes: 28 additions & 67 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,32 @@
<script lang="ts">
export let name: Name;
export let repository: Repository;
const timeZone = "UTC";
// Intl.DateTimeFormat().resolvedOptions().timeZone;
let start = new Date("2013-04-09");
function county(start: Date) {
const now = new Date();
const elapsed = Number(now) - Number(start);
// const offset =
// (start.getTimezoneOffset() - now.getTimezoneOffset()) / 60;
console.log(timeZone, now, start, elapsed);
return convertMS(elapsed);
function convertMS(ms: number) {
let y, mt, w, d, h, m, s;
s = Math.floor(ms / 1000);
m = Math.floor(s / 60);
s = s % 60;
h = Math.floor(m / 60);
m = m % 60;
d = Math.floor(h / 24);
h = h % 24;
w = Math.floor(d / 7);
d = d % 7;
mt = Math.floor(w / 4);
w = w % 4;
y = Math.floor(mt / 12);
mt = 12 - (mt % 12);
return { y, mt, w, d, h, m, s };
}
}
let start = "2013-04-09";
function years(start: Date) {
console.log(start);
const now = new Date();
const elapsed = Number(now) - Number(start);
const year = 1000 * 3600 * 24 * 7 * 4 * 12;
console.log(elapsed / year);
return now.getFullYear() - start.getFullYear();
}
function months(start: Date) {
function county(date: string) {
const now = new Date();
const elapsed = Number(now) - Number(start);
const month = 1000 * 3600 * 24 * 7 * 4;
console.log("month", 12 - ((elapsed / month) % 12));
return Math.trunc(12 - ((elapsed / month) % 12));
return years(start) * 12 + now.getMonth() - start.getMonth();
}
function weeks(start: Date) {
const now = new Date();
const elapsed = Number(now) - Number(start);
const week = 1000 * 3600 * 24 * 7;
console.log("week", 4 - ((elapsed / week) % 4));
return months(start) * 4;
// + now.getMonth() - start.getMonth();
}
function days(start: Date) {
const now = new Date();
const elapsed = Number(now) - Number(start);
const hour = 1000 * 3600;
const day = hour * 24;
console.log("day", (elapsed / day) % 7, (elapsed / hour) % 24);
return Math.trunc(elapsed / day) % 7;
return months(start) * 4 * 7;
// + now.getMonth() - start.getMonth();
const start = new Date(date);
return {
years() {
const elapsed = now.getTime() - start.getTime();
return new Date(elapsed).getFullYear() - 1970;
},
months() {
const elapsed = now.getMonth() - start.getMonth();
return (this.years() * 12 + elapsed) % 12;
},
days() {
const elapsed = now.getDate() - start.getDate();
const count = new Date(
now.getFullYear(),
now.getMonth() + 1,
0,
).getDate();
return (this.months() * count + elapsed) % count;
},
};
}
</script>

Expand All @@ -96,14 +58,13 @@
/>
</label>
</form>
<!-- <pre>
<pre>
{JSON.stringify(county(start), null, 2)}
</pre> -->
</pre>
<h3>{new Date().toLocaleDateString("ru")}</h3>
<h2>{years(new Date(start))} years</h2>
<h2>{months(new Date(start))} months</h2>
<h2>{weeks(new Date(start))} weeks</h2>
<h2>{days(new Date(start))} days</h2>
<h2>{county(start).years()} years</h2>
<h2>{county(start).months()} months</h2>
<h2>{county(start).days()} days</h2>
<h3>{$time}</h3>
</main>

Expand Down

0 comments on commit 9922772

Please sign in to comment.