aboutsummaryrefslogtreecommitdiffhomepage
path: root/nuldoc-src/revision.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-19 04:32:36 +0900
committernsfisis <nsfisis@gmail.com>2023-03-19 04:37:08 +0900
commitf2424f306be40e27c76def020ecb2ce1ec2aad4e (patch)
tree4ab51d9d20707dac51a4a2be60bc476bbac9bdbd /nuldoc-src/revision.ts
parentca7a609fef1167374f7c36ae87be154b0142dd47 (diff)
downloadblog.nsfisis.dev-f2424f306be40e27c76def020ecb2ce1ec2aad4e.tar.gz
blog.nsfisis.dev-f2424f306be40e27c76def020ecb2ce1ec2aad4e.tar.zst
blog.nsfisis.dev-f2424f306be40e27c76def020ecb2ce1ec2aad4e.zip
refactor: change type of Revision.date
Diffstat (limited to 'nuldoc-src/revision.ts')
-rw-r--r--nuldoc-src/revision.ts26
1 files changed, 24 insertions, 2 deletions
diff --git a/nuldoc-src/revision.ts b/nuldoc-src/revision.ts
index 1757694..e04b7ba 100644
--- a/nuldoc-src/revision.ts
+++ b/nuldoc-src/revision.ts
@@ -1,5 +1,27 @@
+export type Date = {
+ year: number;
+ month: number;
+ day: number;
+};
+
+export function stringToDate(s: string): Date {
+ const match = s.match(/(\d{4})-(\d{2})-(\d{2})/);
+ if (match === null) {
+ throw new Error();
+ }
+ const [_, y, m, d] = match;
+ return { year: parseInt(y), month: parseInt(m), day: parseInt(d) };
+}
+
+export function dateToString(date: Date): string {
+ const y = `${date.year}`.padStart(4, "0");
+ const m = `${date.month}`.padStart(2, "0");
+ const d = `${date.day}`.padStart(2, "0");
+ return `${y}-${m}-${d}`;
+}
+
export type Revision = {
number: number;
- date: string; // TODO
- remark: string; // TODO: should it be markup text?
+ date: Date;
+ remark: string;
};