init data-connector

This commit is contained in:
Marcel Arndt
2025-04-10 17:32:06 +02:00
parent 52c1a14609
commit 46631db5b2
105 changed files with 8081 additions and 338 deletions
@@ -0,0 +1,63 @@
import { addDays, Interval, set } from 'date-fns';
import { fromZonedTime } from 'date-fns-tz';
import { generateIntervalForTimeRange } from './helper';
describe('avicennaApiUtilHelper', () => {
describe('generateIntervalForTimeRange', () => {
it('should throw an error when the timeRange format is invalid', () => {
expect(() => generateIntervalForTimeRange('42:00;06:09')).toThrow();
});
it('should generate an interval for the specified time range on the current day', () => {
const result: Interval = {
start: fromZonedTime(
set(new Date(), {
hours: 12,
minutes: 0,
seconds: 0,
milliseconds: 0,
}),
'Europe/Berlin',
),
end: fromZonedTime(
set(new Date(), {
hours: 13,
minutes: 0,
seconds: 0,
milliseconds: 0,
}),
'Europe/Berlin',
),
};
expect(
generateIntervalForTimeRange('12:00-13:00', 'Europe/Berlin'),
).toStrictEqual(result);
});
it('should generate an interval which spans over two days, if the second time is lower than the first', () => {
const result: Interval = {
start: fromZonedTime(
set(new Date(), {
hours: 12,
minutes: 0,
seconds: 0,
milliseconds: 0,
}),
'Europe/Berlin',
),
end: fromZonedTime(
set(addDays(new Date(), 1), {
hours: 1,
minutes: 0,
seconds: 0,
milliseconds: 0,
}),
'Europe/Berlin',
),
};
expect(
generateIntervalForTimeRange('12:00-01:00', 'Europe/Berlin'),
).toStrictEqual(result);
});
});
});