Skip to content

Commit ee032ef

Browse files
committed
refactor: Extract zero
1 parent 9ac4d10 commit ee032ef

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

howm/localDate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { zero } from "../zero.ts";
2+
13
export interface LocalDate {
24
year: number;
35
month: number;
@@ -33,8 +35,6 @@ export const format = (date: LocalDate | LocalDateTime): string =>
3335
"hours" in date ? `T${zero(date.hours)}:${zero(date.minutes)}` : ""
3436
}`;
3537

36-
const zero = (n: number): string => `${n}`.padStart(2, "0");
37-
3838
export const toDate = (date: LocalDate | LocalDateTime): Date => {
3939
const str = format(date);
4040
return new Date(str.includes("T") ? str : `${str}T00:00`);

workflow/EventItem.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Event, getEventStatus, isLink } from "./event.ts";
1010
import { getEnd } from "../howm/Period.ts";
1111
import type { Scrapbox } from "../deps/scrapbox-std-dom.ts";
1212
import { makeLink } from "./path.ts";
13+
import { zero } from "../zero.ts";
1314
declare const scrapbox: Scrapbox;
1415

1516
export const EventItem: FunctionComponent<
@@ -62,5 +63,3 @@ export const EventItem: FunctionComponent<
6263
</li>
6364
);
6465
};
65-
66-
const zero = (n: number): string => `${n}`.padStart(2, "0");

workflow/key.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
startOfWeek,
66
} from "../deps/date-fns.ts";
77
import { LocalDate } from "../howm/localDate.ts";
8+
import { zero } from "../zero.ts";
89

910
export type Key = `${number}-${string}-${string}`;
1011
export type WeekKey = `${number}-w${string}`;
@@ -24,5 +25,3 @@ export const toStartOfWeek = (key: WeekKey): Date => {
2425
const [year, week] = key.split("-w").map((s) => parseInt(s, 10));
2526
return startOfWeek(setWeek(new Date(year, 0, 1), week));
2627
};
27-
28-
const zero = (n: number) => `${n}`.padStart(2, "0");

zero.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const zero = (n: number) => `${n}`.padStart(2, "0");

0 commit comments

Comments
 (0)