generated from github-craftwork/ci-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
959792a
commit 3f8356e
Showing
3 changed files
with
20 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
function getWeekNumber(d) { | ||
function getWeekNumber (d) { | ||
// Copy date so don't modify original | ||
d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())); | ||
// Set to nearest Thursday: current date + 4 - current day number | ||
// Make Sunday's day number 7 | ||
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay()||7)) | ||
// Get first day of year | ||
const yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1)); | ||
// Calculate full weeks to nearest Thursday | ||
const weekNum = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7); | ||
// Return week number | ||
return weekNum; | ||
d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())) | ||
// Set to nearest Thursday: current date + 4 - current day number | ||
// Make Sunday's day number 7 | ||
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7)) | ||
// Get first day of year | ||
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)) | ||
// Calculate full weeks to nearest Thursday | ||
const weekNum = Math.ceil((((d - yearStart) / 86400000) + 1) / 7) | ||
// Return week number | ||
return weekNum | ||
} | ||
|
||
module.exports = (date) => getWeekNumber(date || new Date()); | ||
module.exports = (date) => getWeekNumber(date || new Date()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
const weekNum = require('./index.js'); | ||
const weekNum = require('./index.js') | ||
|
||
test('that weekNum returns a value', () => { | ||
expect(weekNum).not.toBeNull(); | ||
}); | ||
expect(weekNum).not.toBeNull() | ||
}) | ||
|
||
// new test added | ||
test('that weekNum returns a number', () => { | ||
expect(weekNum).toBeDefined(); | ||
}); | ||
expect(weekNum).toBeDefined() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
"standard": "^14.3.1" | ||
}, | ||
"standard": { | ||
"env": [ "jest" ] | ||
"env": [ | ||
"jest" | ||
] | ||
} | ||
} |