# @varyans/schedule-domain

> ## Description

Latest version **1.0.5** (published 2021-01-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @varyans/schedule-domain
pnpm add @varyans/schedule-domain
yarn add @varyans/schedule-domain
bun add @varyans/schedule-domain
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2021-01-09 |
| First published | 2021-01-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 77.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Varazdat Stepanyan |
| Maintainers | varyans |
| Keywords | schedule, type-schedule, schedule domain |

## Links

- npm: https://www.npmjs.com/package/@varyans/schedule-domain
- Repository: https://github.com/varyandeveloper/schedula-domain
- Homepage: https://github.com/varyandeveloper/schedula-domain#readme
- Issues: https://github.com/varyandeveloper/schedula-domain/issues
- npm.io page: https://npm.io/package/@varyans/schedule-domain

## Dependencies (2)

- [pg](https://npm.io/package/pg.md) ^8.5.1
- [moment](https://npm.io/package/moment.md) ^2.29.1

## Recent versions

- 1.0.5 (latest) — 2021-01-09
- 1.0.4 — 2021-01-09
- 1.0.3 — 2021-01-02
- 1.0.2 — 2021-01-02
- 1.0.1 — 2021-01-02
- 1.0.0 — 2021-01-01

## 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

```typescript
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
```typescript

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

```typescript

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. 

## License
[MIT](https://choosealicense.com/licenses/mit/)

## Author

[Varazdat Stepanyan](https://github.com/varyandeveloper)

---
_Source: https://npm.io/package/@varyans/schedule-domain · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
