commit 1b107833652c88c8a954d88ec83feeeb49cd0c7d
parent a9f5e56dcd3b82fbebb63c37fa0fdc82ade71d76
Author: brookjeynes <me@brookjeynes.dev>
Date: Tue, 2 Jun 2026 07:19:14 +1000
feat: add date questions
Signed-off-by: brookjeynes <me@brookjeynes.dev>
Diffstat:
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/index.html b/index.html
@@ -19,7 +19,8 @@
@click="$store.app.changeTab('native')">고유어</button>
<button role="tab" :aria-selected="$store.app.tab === 'time'" id="panel-time"
@click="$store.app.changeTab('time')">시간</button>
- <button role="tab" id="panel-date" disabled>날짜</button>
+ <button role="tab" :aria-selected="$store.app.tab === 'date'" id="panel-date"
+ @click="$store.app.changeTab('date')">날짜</button>
<button role="tab" id="panel-counter" disabled>단위</button>
</div>
diff --git a/src/store.js b/src/store.js
@@ -68,6 +68,8 @@ window.Alpine.store("app", {
hour: 12,
minute: 30,
},
+ /** @type {Date} */
+ date: new Date(),
init() {
this.configSaved = false;
@@ -133,6 +135,16 @@ window.Alpine.store("app", {
return nativeStringFromNumber(this.num);
case "time":
return `${hourStringFromNumber(this.time.hour)}시 ${sinoStringFromNumber(this.time.minute)}분`;
+ case "date":
+ let year = sinoStringFromNumber(this.date.getFullYear());
+ if (year.startsWith("일")) year = year.slice(1);
+
+ // getMonth returns 0 for January
+ let month = sinoStringFromNumber(this.date.getMonth() + 1);
+ if (month === "십") month = "시";
+
+ const day = sinoStringFromNumber(this.date.getDate());
+ return `${year}년 ${month}월 ${day}일`;
default:
throw new Error("unknown tab selected");
}
@@ -146,6 +158,12 @@ window.Alpine.store("app", {
return this.num.toString();
case "time":
return `${this.time.hour.toString().padStart(2, "0")}:${this.time.minute.toString().padStart(2, "0")}`;
+ case "date":
+ const year = this.date.getFullYear();
+ // getMonth returns 0 for January
+ const month = this.date.getMonth() + 1;
+ const day = this.date.getDate();
+ return `${year}년 ${month}월 ${day}일`;
default:
throw new Error("unknown tab selected");
}
@@ -226,6 +244,9 @@ window.Alpine.store("app", {
case "time":
this.time = this.randomNumber;
break;
+ case "date":
+ this.date = this.randomNumber;
+ break;
default:
throw new Error("unknown tab selected");
}
@@ -243,6 +264,8 @@ window.Alpine.store("app", {
hour: random(1, 13),
minute: random(0, 60),
};
+ case "date":
+ return randomDate(new Date(1960, 0, 1), new Date());
default:
throw new Error("unknown tab selected");
}
@@ -257,3 +280,13 @@ window.Alpine.store("app", {
function random(min, max) {
return Math.floor(Math.random() * (max - min) + min);
};
+
+/**
+ * @param {Date} start
+ * @param {Date} end
+ * @returns {Date}
+ */
+function randomDate(start, end) {
+ return new Date(+start + Math.random() * (end - start));
+}
+
diff --git a/src/time.js b/src/time.js
@@ -1,5 +1,9 @@
import { nativeStringFromNumber } from "./native.js";
+/**
+ * @param {number} num
+ * @returns {string}
+ */
export function hourStringFromNumber(num) {
const str = nativeStringFromNumber(num);