-
-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathpost.ts
More file actions
31 lines (27 loc) · 627 Bytes
/
post.ts
File metadata and controls
31 lines (27 loc) · 627 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const SCHEDULED = "scheduled" as const;
const PUBLISHED = "published" as const;
const DRAFT = "draft" as const;
export type PostStatus = typeof SCHEDULED | typeof PUBLISHED | typeof DRAFT;
export const status = {
SCHEDULED,
PUBLISHED,
DRAFT,
};
export function getPostStatus(published: Date | null, now = new Date()) {
if (!published) {
return DRAFT;
}
if (published > now) {
return SCHEDULED;
}
return PUBLISHED;
}
export function isValidScheduleTime(
scheduleTime: string | undefined,
now = new Date(),
) {
if (!scheduleTime) {
return false;
}
return new Date(scheduleTime) < now;
}