I've spent a lot of time searching for code to help me calculate the week number in my Angular app according to ISO standards. It's been challenging to find JavaScript-specific code, but I believe I may have found something - however, I encountered an error: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
I'm completely stumped by this error message. Below is a sample service that I attempted to use with the code:
import { Injectable } from '@angular/core';
@Injectable()
export class WeekNumberService {
constructor() { }
ISO8601_week_no(dt) {
var tdt = new Date(dt.valueOf());
var dayn = (dt.getDay() + 6) % 7;
tdt.setDate(tdt.getDate() - dayn + 3);
var firstThursday = tdt.valueOf();
tdt.setMonth(0, 1);
if (tdt.getDay() !== 4)
{
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
}
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
}
}
Note: My main goal is to determine the week number only.