diff --git a/packages/client/src/utils/__tests__/utils.test.ts b/packages/client/src/utils/__tests__/utils.test.ts
index fb74bab9c..c31823026 100644
--- a/packages/client/src/utils/__tests__/utils.test.ts
+++ b/packages/client/src/utils/__tests__/utils.test.ts
@@ -38,6 +38,7 @@ describe("Helpers", () => {
});
test("should convert string to number", () => {
+ const halfStr = "21:00 - 21:20";
const oneStr = "16:00 - 17:00";
const oneHalfStr = "22:00 - 23:30";
const twoStr = "22:00 - 24:00";
@@ -46,9 +47,11 @@ describe("Helpers", () => {
// const morningResult = convertIntervalToNum(morningStr);
const oneResult = calculateIntervalDuration(oneStr);
const oneHalfResult = calculateIntervalDuration(oneHalfStr);
+ const halfResult = calculateIntervalDuration(halfStr);
const twoResult = calculateIntervalDuration(twoStr);
const nonStdResult = calculateIntervalDuration(nonStdStr);
+ expect(halfResult).toBe(0.5);
expect(oneResult).toBe(1);
expect(oneHalfResult).toBe(1.5);
expect(twoResult).toBe(2);
diff --git a/packages/client/src/utils/helpers.ts b/packages/client/src/utils/helpers.ts
index 53dd2b8f5..372bf5f27 100644
--- a/packages/client/src/utils/helpers.ts
+++ b/packages/client/src/utils/helpers.ts
@@ -102,6 +102,7 @@ const getMillisFromMidnight = (time: string) =>
* @param {string | null} interval - String slot interval
* Converts a string slot interval to a number e.g:
* `null => 0`;
+ * `"21:00 - 21:20" => 0.5`;
* `"16:00 - 17:00" => 1.0`;
* `"22:00 - 23:30" => 1.5`;
* `"22:00 - 24:00" => 2`;
@@ -118,11 +119,7 @@ export const calculateIntervalDuration = (interval: string | null) => {
const diffMillis =
getMillisFromMidnight(endTime) - getMillisFromMidnight(startTime);
- return diffMillis <= hourInMillis
- ? 1
- : diffMillis <= hourInMillis * 1.5
- ? 1.5
- : 2;
+ return Math.ceil((diffMillis / hourInMillis) * 2) * 0.5;
};
/**
* interpolate text including
diff --git a/packages/ui/src/IntervalCard/BookingCardContainer.tsx b/packages/ui/src/IntervalCard/BookingCardContainer.tsx
index 26d8ea2b7..9f9f25309 100644
--- a/packages/ui/src/IntervalCard/BookingCardContainer.tsx
+++ b/packages/ui/src/IntervalCard/BookingCardContainer.tsx
@@ -29,6 +29,7 @@ const BookingCardContainer: React.FC = ({
};
const containerSizeLookup = {
+ [IntervalDuration["0.5h"]]: ["w-[200px]", "min-h-[110px]", "px-4", "py-2.5"],
[IntervalDuration["1h"]]: ["w-[220px]", "min-h-[110px]", "px-4", "py-2.5"],
[IntervalDuration["1.5h"]]: ["w-[320px]", "h-[128px]", "px-4", "py-3"],
[IntervalDuration["2h"]]: ["w-[401px]", "h-[146px]", "px-4", "py-3"],
diff --git a/packages/ui/src/IntervalCard/CardContent.tsx b/packages/ui/src/IntervalCard/CardContent.tsx
index 055590aac..28b1adf61 100644
--- a/packages/ui/src/IntervalCard/CardContent.tsx
+++ b/packages/ui/src/IntervalCard/CardContent.tsx
@@ -80,6 +80,7 @@ const getTimestringClasses = (
].join(" ");
const timestringBookingSizeLookup = {
+ [IntervalDuration["0.5h"]]: ["mb-2", "text-md", "leading-8", "font-semibold"],
[IntervalDuration["1h"]]: ["mb-2", "text-lg", "leading-8", "font-semibold"],
[IntervalDuration["1.5h"]]: [
"mb-2",
diff --git a/packages/ui/src/IntervalCard/__tests__/intervalCardUtils.test.ts b/packages/ui/src/IntervalCard/__tests__/intervalCardUtils.test.ts
index e2445fe09..63418b3bf 100644
--- a/packages/ui/src/IntervalCard/__tests__/intervalCardUtils.test.ts
+++ b/packages/ui/src/IntervalCard/__tests__/intervalCardUtils.test.ts
@@ -21,6 +21,10 @@ const runCalculateDurationTableTests = (tests: TestParams[]) => {
describe("IntervalCard", () => {
describe("calculateDuration util", () => {
runCalculateDurationTableTests([
+ { startTime: "09:00", endTime: "09:15", want: IntervalDuration["0.5h"] },
+ { startTime: "09:00", endTime: "09:20", want: IntervalDuration["0.5h"] },
+ { startTime: "09:00", endTime: "09:30", want: IntervalDuration["0.5h"] },
+
{ startTime: "09:00", endTime: "09:40", want: IntervalDuration["1h"] },
{ startTime: "09:00", endTime: "09:50", want: IntervalDuration["1h"] },
{ startTime: "09:00", endTime: "10:00", want: IntervalDuration["1h"] },
diff --git a/packages/ui/src/IntervalCard/types.ts b/packages/ui/src/IntervalCard/types.ts
index 19cf9888e..2435ab0ef 100644
--- a/packages/ui/src/IntervalCard/types.ts
+++ b/packages/ui/src/IntervalCard/types.ts
@@ -17,6 +17,7 @@ export enum IntervalCardVariant {
}
export enum IntervalDuration {
+ "0.5h",
"1h",
"1.5h",
"2h",
diff --git a/packages/ui/src/IntervalCard/utils.ts b/packages/ui/src/IntervalCard/utils.ts
index 1a192a701..bdf275587 100644
--- a/packages/ui/src/IntervalCard/utils.ts
+++ b/packages/ui/src/IntervalCard/utils.ts
@@ -17,9 +17,6 @@ export const calculateDuration = (startTime: string, endTime: string) => {
const diffMillis =
getMillisFromMidnight(endTime) - getMillisFromMidnight(startTime);
- return diffMillis <= hourInMillis
- ? IntervalDuration["1h"]
- : diffMillis <= hourInMillis * 1.5
- ? IntervalDuration["1.5h"]
- : IntervalDuration["2h"];
+ const duration = `${Math.ceil((diffMillis / hourInMillis) * 2) * 0.5}h`;
+ return IntervalDuration[duration];
};