Skip to content
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

Fix startOf function for isoWeek #23

Merged
merged 12 commits into from
Aug 10, 2020
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ Chart._adapters._date.override({
_create: function(time) {
return DateTime.fromMillis(time, this.options);
},


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove this newly added whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* @private
*/
_isoWeekday: function(dateTime, weekday){
benmccann marked this conversation as resolved.
Show resolved Hide resolved
var normalizedWeekday = weekday % 7 ? weekday % 7 : 7;
benmccann marked this conversation as resolved.
Show resolved Hide resolved
var diff = dateTime.weekday < normalizedWeekday ? normalizedWeekday - dateTime.weekday - 7 : normalizedWeekday - dateTime.weekday;
return dateTime.plus({days: diff}).startOf('day');
},

formats: function() {
return FORMATS;
},
Expand Down Expand Up @@ -72,7 +81,7 @@ Chart._adapters._date.override({

startOf: function(time, unit, weekday) {
if (unit === 'isoWeek') {
return this._create(time).isoWeekday(weekday).valueOf();
return this._isoWeekday(this._create(time), Math.abs(weekday)).valueOf();
}
return unit ? this._create(time).startOf(unit).valueOf() : time;
},
Expand Down