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
25eb651
commit 3ba9945
Showing
4 changed files
with
22 additions
and
20 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() | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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