Skip to content

Commit

Permalink
Formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
NodeCodeFormatter committed Oct 14, 2019
1 parent 25eb651 commit 3ba9945
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
24 changes: 12 additions & 12 deletions index.js
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())
10 changes: 5 additions & 5 deletions index.test.js
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()
})
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "jest",
"build":"npx parcel build index.js",
"build": "npx parcel build index.js",
"lint": "npx standard --fix"
},
"repository": {
Expand All @@ -25,6 +25,8 @@
"standard": "^14.3.1"
},
"standard": {
"env": [ "jest" ]
"env": [
"jest"
]
}
}

0 comments on commit 3ba9945

Please sign in to comment.