From ebd03958a5ccdc8ed677957aecc43b3506614573 Mon Sep 17 00:00:00 2001 From: peter279k Date: Fri, 19 Jul 2019 22:07:02 +0800 Subject: [PATCH] Add isWeekend code snippets --- snippets/isWeekend.md | 16 ++++++++++++++++ tag_database | 1 + test/isWeekend.test.js | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 snippets/isWeekend.md create mode 100644 test/isWeekend.test.js 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..2a08c84e7 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:uncategorized 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); +});