Skip to content

Commit 883d342

Browse files
authored
Merge pull request #360 from openscript-ch/359-gap-detection-in-period-picker-cannot-be-satisfied
359 gap detection in period picker cannot be satisfied
2 parents 3a1f3e0 + f82bcd0 commit 883d342

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

.changeset/three-ladybugs-dress.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@quassel/frontend": patch
3+
"@quassel/utils": patch
4+
---
5+
6+
Fix always setting start date to start of month

apps/frontend/src/routes/_auth/questionnaire/_questionnaire/new.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { $api } from "../../../../stores/api";
66
import { $questionnaire } from "../../../../stores/questionnaire";
77
import { useEffect } from "react";
88
import { Title } from "@quassel/ui";
9-
import { getNext } from "@quassel/utils";
9+
import { getNext, getStartOf } from "@quassel/utils";
1010

1111
const messages = i18n("questionnaireNew", {
1212
title: "Create new period of life",
@@ -35,7 +35,10 @@ function QuestionnaireNew() {
3535

3636
const prevEndDate = questionnaire?.participant.latestQuestionnaire?.endedAt;
3737

38-
const startDate = prevEndDate ? getNext("month", new Date(prevEndDate)) : participant?.birthday ? new Date(participant.birthday) : undefined;
38+
const startFromBirthday = participant?.birthday ? getStartOf("month", new Date(participant.birthday)) : undefined;
39+
const startFromPrevious = prevEndDate ? getNext("month", new Date(prevEndDate)) : undefined;
40+
41+
const startDate = startFromPrevious ?? startFromBirthday;
3942

4043
const onSave = (form: PeriodFormValues) => {
4144
const {

libs/utils/src/date.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@ export function formatDate(date: Date, dayjsFormatTemplate: string) {
1111

1212
export const getTime = (date: Date) => formatDate(date, "HH:mm");
1313

14-
export const getNext = (unit: dayjs.ManipulateType, date: Date) => {
15-
return dayjs(date).utc().add(1, unit).startOf(unit).toDate();
16-
};
14+
export const getNext = (unit: dayjs.ManipulateType, date: Date) => dayjs(date).utc().add(1, unit).startOf(unit).toDate();
1715

18-
export const isSame = (unit: dayjs.ManipulateType, left: Date, right = new Date()) => {
19-
return dayjs(left).isSame(right, unit);
20-
};
16+
export const getStartOf = (unit: dayjs.ManipulateType, date: Date) => dayjs(date).utc().startOf(unit).toDate();
2117

22-
export const isSameOrAfter = (left: Date, right: Date, unit: dayjs.ManipulateType) => {
23-
return dayjs(left).isAfter(dayjs(right).startOf(unit));
24-
};
18+
export const isSame = (unit: dayjs.ManipulateType, left: Date, right = new Date()) => dayjs(left).isSame(right, unit);
19+
export const isSameOrAfter = (left: Date, right: Date, unit: dayjs.ManipulateType) => dayjs(left).isAfter(dayjs(right).startOf(unit));
2520

2621
export function getDateFromTimeAndWeekday(time: string, weekday: number) {
2722
return dayjs(time, "HH:mm:ss")

libs/utils/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { formatDate, getTime, getDateFromTimeAndWeekday, getNext, isSameOrAfter, isSame } from "./date";
1+
export { formatDate, getTime, getDateFromTimeAndWeekday, getNext, isSameOrAfter, isSame, getStartOf } from "./date";
22

33
export { type Gap, type GapsPerDay, groupByWeekday, resolveGaps, entriesByInterval } from "./entry";

0 commit comments

Comments
 (0)