Merge pull request #1000 from peter279k/add_is_weekend

[FEATURE] Add isWeekend code snippets
This commit is contained in:
Angelos Chalaris
2019-07-19 19:20:31 +03:00
committed by GitHub
3 changed files with 33 additions and 0 deletions

16
snippets/isWeekend.md Normal file
View File

@ -0,0 +1,16 @@
### isWeekend
Results in a boolean representation of a specific date.
Pass the specific date object firstly.
Use `Date.getDay()` to check weekend then return a boolean.
```js
const isWeekend = (t = new Date()) => {
return t.getDay() === 0 || t.getDay() === 6;
};
```
```js
isWeekend(); // 2018-10-19 (if current date is 2018-10-18)
```

View File

@ -173,6 +173,7 @@ isUndefined:type,beginner
isUpperCase:string,utility,beginner
isValidJSON:type,json,intermediate
isWeekday:date,beginner
isWeekend:date,beginner
isWritableStream:node,type,intermediate
join:array,intermediate
JSONtoCSV:array,string,object,advanced

16
test/isWeekend.test.js Normal file
View File

@ -0,0 +1,16 @@
const {isWeekend} = require('./_30s.js');
test('isWeekend is a Function', () => {
expect(isWeekend).toBeInstanceOf(Function);
});
test('Returns the correct type', () => {
expect(typeof isWeekend()).toBe('boolean');
});
const friday = new Date('2019-07-19');
const saturday = new Date('2019-07-20');
test('Returns true', () => {
expect(isWeekend(friday)).toBe(false);
});
test('Returns false', () => {
expect(isWeekend(saturday)).toBe(true);
});