Skip to content

Commit

Permalink
feat(time-slots): add support to full date
Browse files Browse the repository at this point in the history
  • Loading branch information
lparolari committed Oct 14, 2020
1 parent fadddc9 commit 466ca92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/__tests__/slots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ describe("slots", () => {
it("generate a single time slot", () => {
const gen = slots(interval)([])(start);

expect(gen.next().value).toEqual([start.format("HH:mm")]);
expect(gen.next().value).toEqual([start]);
});

it("generate subsequent time slots", () => {
const gen = slots(interval)([])(start);

expect(gen.next().value).toEqual([start.format("HH:mm")]);
expect(gen.next().value).toEqual([addInterval(interval)(start).format("HH:mm")]);
expect(gen.next().value).toEqual([start]);
expect(gen.next().value).toEqual([addInterval(interval)(start)]);
});

it("do not generate time slots if constraints always fail", () => {
Expand All @@ -35,7 +35,7 @@ describe("slots", () => {
const gen = slots(interval)([geq(d2)])(start);

expect(gen.next().value).toEqual([]);
expect(gen.next().value).toEqual([d2.format("HH:mm")]);
expect(gen.next().value).toEqual([d2]);
expect(gen.next().value).not.toEqual([]);
});

Expand All @@ -44,7 +44,7 @@ describe("slots", () => {

expect(gen.next().value).toEqual([]);
expect(gen.next().value).toEqual([]);
expect(gen.next().value).toEqual([d3.format("HH:mm")]);
expect(gen.next().value).toEqual([d3]);
expect(gen.next().value).not.toEqual([]);
});
});
2 changes: 1 addition & 1 deletion src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import * as R from "ramda";
const repeat = (n: number) => R.repeat(0, n);

export const take = (n: number) => (iterable: IterableIterator<Slot>): Slot[] =>
R.map(() => iterable.next().value as string[], repeat(n));
R.map(() => iterable.next().value, repeat(n));

export const flatten = R.flatten;
6 changes: 3 additions & 3 deletions src/slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type Interval = {
unit: moment.DurationInputArg2;
};

export type Slot = string[];
export type Slot = Moment[];

export const generator = (interval: Interval) => (constraints: Constraint[]) => (
start: Moment,
Expand All @@ -26,11 +26,11 @@ export const generator = (interval: Interval) => (constraints: Constraint[]) =>
export const slots = generator;

export const one = (constraints: Constraint[]) => (start: Moment): Slot => {
const current = moment(start, "HH:mm");
const current = start;

if (!validate(constraints)(current)) {
return [];
}

return [current.format("HH:mm")];
return [current];
};

0 comments on commit 466ca92

Please sign in to comment.