I have been looking around allot for code to use in my program that will calculate the week number (according to ISO standards) in my Angular app using typescript. It is very hard to find a piece of code just in JavaScript, but I think I may have found something- problem is I get an error: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
I have NO idea what this means. Here is a service that I have tried to write to use 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);
}
}
PS: I am in the end only looking for the week number.