Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
reedws committed Jan 31, 2022
1 parent 7d27e9b commit 5440be5
Showing 1 changed file with 83 additions and 17 deletions.
100 changes: 83 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ This is a plugin for Day.js that allows for Date calculations to take place that
- [businessDaysInMonth() => [Day.js Object]](#businessdaysinmonth--dayjs-object)
- [lastBusinessDayOfMonth() => Day.js Object](#lastbusinessdayofmonth--dayjs-object)
- [businessWeeksInMonth() => [[Day.js Object]]](#businessweeksinmonth--dayjs-object)
- [getHolidays() => [string]](#getholidays--string)
- [setHolidays() => void](#setholidays--void)
- [getHolidayFormat() => string](#getholidayformat--string)
- [setHolidayFormat() => void](#setholidayformat--void)
- [getWorkingWeekdays() => [number]](#getworkingweekdays--number)
- [setWorkingWeekdays() => void](#setworkingweekdays--void)
- [Local Development and Contributing](#local-development-and-contributing)

## Getting Started
Expand Down Expand Up @@ -74,13 +80,13 @@ Check if the date is a holiday. Returns **true** or **false**
```javascript
// Add holidays to plugin options
const options = {
holidays: ['2020-12-25'],
holidayFormat: 'YYYY-MM-DD',
holidays: [`2020-12-25`],
holidayFormat: `YYYY-MM-DD`,
};
dayjs.extend(businessDays, options);

// Christmas day is a Friday
dayjs('2020-12-25').isHoliday(); // returns true
dayjs(`2020-12-25`).isHoliday(); // returns true
```

### isBusinessDay() => Boolean
Expand All @@ -89,10 +95,10 @@ Check if the date is a business day. Returns **true** or **false**

```javascript
// Christmas day is a Friday
dayjs('2020-12-25').isBusinessDay(); // returns true
dayjs(`2020-12-25`).isBusinessDay(); // returns true

// Boxing day is a Saturday
dayjs('2020-12-26').isBusinessDay(); // returns false
dayjs(`2020-12-26`).isBusinessDay(); // returns false
```

### businessDaysAdd(number) => Day.js Object
Expand All @@ -102,7 +108,7 @@ dayjs('2020-12-26').isBusinessDay(); // returns false
Adds the `number` of Business Days to the current date. Returns the new date as a **Day.js object**

```javascript
dayjs('2020-12-25').businessDaysAdd(3).format('DD/MM/YYYY'); // returns 30/12/2020
dayjs(`2020-12-25`).businessDaysAdd(3).format(`DD/MM/YYYY`); // returns 30/12/2020
```

### businessDaysSubtract(number) => Day.js Object
Expand All @@ -112,7 +118,7 @@ dayjs('2020-12-25').businessDaysAdd(3).format('DD/MM/YYYY'); // returns 30/12/20
Subtracts the `number` of Business Days from the current date. Returns the new date as a **Day.js object**

```javascript
dayjs('2020-12-30').businessDaysSubtract(3).format('DD/MM/YYYY'); // returns 25/12/2020
dayjs(`2020-12-30`).businessDaysSubtract(3).format(`DD/MM/YYYY`); // returns 25/12/2020
```

### businessDiff(date) => Number
Expand All @@ -122,8 +128,8 @@ dayjs('2020-12-30').businessDaysSubtract(3).format('DD/MM/YYYY'); // returns 25/
Calculates the number of business days between a Day.js date and `date`. Returns the difference as a **positive or negative number**.

```javascript
dayjs('2020-12-25').businessDiff(dayjs('2020-12-30')); // returns -5
dayjs('2020-12-30').businessDiff(dayjs('2020-12-25')); // returns 5
dayjs(`2020-12-25`).businessDiff(dayjs(`2020-12-30`)); // returns -5
dayjs(`2020-12-30`).businessDiff(dayjs(`2020-12-25`)); // returns 5
```

### nextBusinessDay() => Day.js Object
Expand All @@ -132,7 +138,7 @@ Calculates the next Business Day. Returns a **Day.js object**

```javascript
// 25th December 2020 is a Friday. Next business day is Monday 28th December.
dayjs('2020-12-25').nextBusinessDay().format('DD/MM/YYYY'); // returns 28/12/2020
dayjs(`2020-12-25`).nextBusinessDay().format(`DD/MM/YYYY`); // returns 28/12/2020
```

### prevBusinessDay() => Day.js Object
Expand All @@ -141,16 +147,16 @@ Calculates the previous Business Day. Returns a **Day.js object**

```javascript
// 28th December 2020 is a Monday. Previous business day is Friday 25th December.
dayjs('2020-12-28').prevBusinessDay().format('DD/MM/YYYY'); // returns 25/12/2020
dayjs(`2020-12-28`).prevBusinessDay().format(`DD/MM/YYYY`); // returns 25/12/2020
```

### businessDaysInMonth() => [Day.js Object]

Calculates all of the business days in a given month. Returns an array of **Day.js objects**

```javascript
dayjs('2020-12-25').businessDaysInMonth();
// returns equivalent of [dayjs('2020-12-01'), dayjs('2020-12-02'), ...]
dayjs(`2020-12-25`).businessDaysInMonth();
// returns equivalent of [dayjs(`2020-12-01`), dayjs(`2020-12-02`), ...]
```

### lastBusinessDayOfMonth() => Day.js Object
Expand All @@ -159,23 +165,83 @@ Calculates the last Business Day of the month. Returns a **Day.js object**

```javascript
// 30th September 2021 is a Thursday and is the last business day of the month.
dayjs('2021-09-01').lastBusinessDayOfMonth().format('DD/MM/YYYY'); // returns 30/09/2021
dayjs(`2021-09-01`).lastBusinessDayOfMonth().format(`DD/MM/YYYY`); // returns 30/09/2021
```

### businessWeeksInMonth() => [[Day.js Object]]

Calculates all of the business weeks and days in a given month. Returns an two dimensional array of **Day.js objects**

```javascript
dayjs('2020-12-25').businessWeeksInMonth();
dayjs(`2020-12-25`).businessWeeksInMonth();
// returns equivalent of
// [
// [dayjs('2020-12-01'), dayjs('2020-12-02'), ...],
// [dayjs('2020-12-07'), dayjs('2020-12-08'), ...],
// [dayjs(`2020-12-01`), dayjs(`2020-12-02`), ...],
// [dayjs(`2020-12-07`), dayjs(`2020-12-08`), ...],
// ...
// ]
```

### getHolidays() => [string]

Returns an array of **strings** representing the currently set holidays

```javascript
const options = {
holidays: [`2020-12-25`],
holidayFormat: `YYYY-MM-DD`,
};
dayjs.extend(businessDays, options);

dayjs.getHolidays(); // returns [ `2020-12-25` ]
```

### setHolidays() => void

Sets the holiday list to the given array of **strings**

```javascript
dayjs.setHolidays([ `2020-12-25`, `2021-01-01` ]);
```

### getHolidayFormat() => string

Returns a **string** representing the currently expected holiday format

```javascript
const options = {
holidays: [`2020-12-25`],
holidayFormat: `YYYY-MM-DD`,
};
dayjs.extend(businessDays, options);

dayjs.getHolidaysFormat(); // returns [ `YYYY-MM-DD` ]
```

### setHolidayFormat() => void

Sets the holiday list to the given a **string**

```javascript
dayjs.setHolidayFormat(`MM-DD-YYYY`);
```

### getWorkingWeekdays() => [number]

Returns an array of **numbers** representing the current days fo the week that are considered business days

```javascript
dayjs.getWorkingWeekdays(); // returns [ 1, 2, 3, 4, 5 ]
```

### setWorkingWeekdays() => void

Sets the days of the week that are considered business days to the given array of **numbers** where 0 is Sunday and 6 is Saturday

```javascript
dayjs.setWorkingWeekdays([ 0, 3, 4, 5 ]);
```

## Local Development and Contributing

I am more than happy to accept PRs for bugs, improvements or new features.
Expand Down

0 comments on commit 5440be5

Please sign in to comment.