Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Valexr committed Apr 13, 2024
1 parent cb00dff commit f3052e2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "county",
"description": "Tiny counter",
"version": "0.1.0",
"private": true,
"type": "module",
Expand Down
58 changes: 40 additions & 18 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,66 @@
export let repository: Repository;
const timeZone = "UTC";
// Intl.DateTimeFormat().resolvedOptions().timeZone;
const start = new Date("2013-04-09");
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,
new Date(now),
new Date(start),
elapsed,
);
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;
s = s % 60;
h = Math.floor(m / 60);
// m = m % 60;
m = m % 60;
d = Math.floor(h / 24);
// h = h % 24;
h = h % 24;
w = Math.floor(d / 7);
// d = d % 7;
d = d % 7;
mt = Math.floor(w / 4);
// w = w % 4;
w = w % 4;
y = Math.floor(mt / 12);
// mt = mt % 12;
mt = 12 - (mt % 12);
return { y, mt, w, d, h, m, s };
}
}
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) {
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();
}
Expand All @@ -78,14 +87,24 @@
</header>

<main>
<pre>
<form action="POST" on:submit|preventDefault>
<label>
<input
type="date"
placeholder="Set start date"
bind:value={start}
/>
</label>
</form>
<!-- <pre>
{JSON.stringify(county(start), null, 2)}
</pre>
<h1>{$time}</h1>
</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>
<h3>{$time}</h3>
</main>

<footer>
Expand All @@ -94,4 +113,7 @@

<style>
@import "app.css";
main {
padding: 1em;
}
</style>
File renamed without changes.
7 changes: 3 additions & 4 deletions src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ function createTimer() {
}
}

export const time = readable(new Date(), (set) => {
set(new Date());

export const time = readable(new Date().toLocaleTimeString('ru'), (set) => {
const interval = setInterval(() => {
set(new Date());
const date = new Date().toLocaleTimeString('ru')
set(date);
}, 1000);

return () => clearInterval(interval);
Expand Down
5 changes: 0 additions & 5 deletions src/types.ts

This file was deleted.

0 comments on commit f3052e2

Please sign in to comment.