diff options
Diffstat (limited to 'nuldoc-src/revision.ts')
| -rw-r--r-- | nuldoc-src/revision.ts | 26 |
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; }; |
