README
Typescript Schedule Domain
Description
You could use this package to easily solve schedule required systems.
It doesn't matter witch date you are passing to check. Week time represented as units from 0 to 10080. One day 24 hours is equal to 1440 units
- Add as many schedules as required per day
- Add start in day 1 and close on next day(s)
- Office, Restaurant open/closed for given time
- Schools is there a date intersection for classrooms
Installation
npm i @varyans/schedule-domain
Examples
Note. make sure the timezone is correct (node, database) before using it.
Create schedules
import { scheduleServiceFactory } from '@varyans/schedule-domain';
const scheduleService = scheduleServiceFactory();
scheduleService.bulkCreate(
{
day: 0, // Sunday
end: '21:30',
start: '09:30',
},
{
day: 1, // Monday
end: '21:30',
start: '09:30',
},
{
day: 2, // Tuesday
end: '21:30',
start: '09:30',
},
{
day: 3, // Wednesday
end: '21:30',
start: '09:30',
},
{
day: 4, // Thursday
end: '21:30',
start: '09:30',
},
{
day: 5, // Friday
end: '21:30',
start: '09:30',
},
{
day: 6, // Saturday
end: '21:30',
start: '09:30',
}
).then(r => {});
Check is there a date range containing given date
import { scheduleServiceFactory } from '@varyans/schedule-domain';
const scheduleService = scheduleServiceFactory();
scheduleService.hasRangeContainingDate(new Date('2021-01-03 21:29')).then(r => {
console.log(r === true ? 'Date in range' : 'No range containing diven date');
});
Check is there a date range intersection
import { scheduleServiceFactory } from '@varyans/schedule-domain';
const scheduleService = scheduleServiceFactory();
scheduleService.hasIntersection(new Date('2021-01-03 14:29'), new Date('2021-01-03 16:10')).then(r => {
console.log(r === true ? 'Has intersection' : 'No intersections');
});
Add new repository providers
- Create .env file if not exists
- Add
SCHEDULE_CONFIG_PATH
=path-to-your-config-file - Copy content from package config file
- Add new database provider mongo, mysql or something else
- Create repository object for that provider
- Add factory path for provider repository in config file
- Use provider name when creating instance of schedule service
Tests
All packages functionality test is covered by jest
Supported repositories
- Array
- Postgres
- Postgres repository will automatically create a table with name specified in your custom config or with default "schedules" name.