-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add setWeek fucntion to weekOfYear #368
Conversation
Codecov Report
@@ Coverage Diff @@
## master #368 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 56 56
Lines 491 495 +4
Branches 76 79 +3
=====================================
+ Hits 491 495 +4
Continue to review full report at Codecov.
|
You should add tests so the code coverage remains at 100%. |
@naulacambra added
please tell me how to fix? |
You're comparing a The first test, works because the function expect(dayjs().week()).toBe(moment().week()) // expect([int]).toBe([int]) - apples to apples
expect(dayjs().setWeek(week)).toBe(moment().week(week)) // expect([dayjs]).toBe([moment]) - apples to oranges You should change the test to expect(dayjs().setWeek(week).week()).toBe(moment().week(week).week()) // expect([int]).toBe([int]) - apples to apples And also, add another test like expect(dayjs().setWeek(week).date()).toBe(moment().week(week).date()) // expect([int]).toBe([int]) - apples to apples I hope it helps |
BTW, reviewing again this PR, I noticed that you are adding a new method,
Since this lib bases its API on And by other hand, could you add an alias,
|
src/plugin/weekOfYear/index.js
Outdated
@@ -2,7 +2,12 @@ import { MS, Y, D, W } from '../../constant' | |||
|
|||
export default (o, c, d) => { | |||
const proto = c.prototype | |||
proto.week = function () { | |||
proto.week = function (week = 0) { | |||
if (week > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking if week
is positive, you should check if it's undefined.
Momentjs allows set a negative week
console.log(moment('2018-01-20').week(-1).format()); // "2017-12-23T00:00:00+01:00"
So I think that we should as well
src/plugin/weekOfYear/index.js
Outdated
@@ -12,4 +15,7 @@ export default (o, c, d) => { | |||
const diffInWeek = this.diff(compareDay, W, true) | |||
return Math.ceil(diffInWeek) | |||
} | |||
proto.weeks = function (week = 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be aware that, if user call weeks
alias, without arguments, the default value week = 0
will set the week to 0.
dayjs('2018-01-01').week() // 1
dayjs('2018-01-01').weeks() // 0
You should change the default value to null
, the same for week()
proto.weeks = function (week = null) {
return this.week(week)
}
@naulacambra sorry, did not pay attention. Fixed |
🎉 This PR is included in version 1.8.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
No description provided.