Skip to content

Commit

Permalink
Fix getWeekOfYear reporting wrong week when first day of year is not …
Browse files Browse the repository at this point in the history
…a Monday (#99)

* fix linting

* Fix getWeekOfYear function

* Correct weekday offset
  • Loading branch information
bameyrick authored Feb 3, 2025
1 parent 63303e4 commit ebc193f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = function (config) {

client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
captureConsole: true,
jasmine: {
random: false,
},
Expand All @@ -42,7 +43,7 @@ module.exports = function (config) {
reporters: [{ type: 'lcovonly' }, { type: 'text' }],
},

reporters: ['spec', 'coverage'],
reporters: ['progress', 'coverage'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
Expand Down
3 changes: 2 additions & 1 deletion src/dates/getters/getWeekOfYear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { getStartOfYear } from './getStartOfYear.js';
*/
export function getWeekOfYear(date: Date = new Date()): number {
const firstDayOfYear = getStartOfYear(date);
const offset = firstDayOfYear.getDay() + 1;

const days = convertTimeUnit(date.getTime() - firstDayOfYear.getTime(), TimeUnit.Milliseconds, TimeUnit.Days);

return Math.ceil(days / 7);
return Math.ceil((days + offset) / 7);
}
2 changes: 1 addition & 1 deletion src/type-predicates/isPlainObject.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe(`isPlainObject`, () => {
});

it('should return `false` if the object is not created by the `Object` constructor.', () => {
function Foo() {
function Foo(this: any) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
this.abc = {};
}
Expand Down

0 comments on commit ebc193f

Please sign in to comment.