diff --git a/snippets/isWeekend.md b/snippets/isWeekend.md new file mode 100644 index 000000000..e3d0a1529 --- /dev/null +++ b/snippets/isWeekend.md @@ -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) +``` diff --git a/tag_database b/tag_database index 2ee3c14f4..355c34070 100644 --- a/tag_database +++ b/tag_database @@ -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 diff --git a/test/isWeekend.test.js b/test/isWeekend.test.js new file mode 100644 index 000000000..ec5e06dd4 --- /dev/null +++ b/test/isWeekend.test.js @@ -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); +});