Skip to content

Add function to Date prototype and keep other methods #7726

@mbakker96

Description

@mbakker96

Hello,

I want to add a function to the Date prototype. I want to add a weekNumber function to it that returns the number of the week.

I wan to create make it on the typescript way so much as posible.

This is the prototype function:

Date.prototype.getWeekNumber()
    var d: Date = new Date(+this);
    d.setHours(0, 0, 0);
    d.setDate(d.getDate() + 4 - (d.getDay() || 7));
    return Math.ceil((((d - new Date(d.getFullYear(), 0, 1)) / 8.64e7) + 1) / 7);
};

I created a interface but the problem was that he removed all the functions of the Date and becease of that my IDE was giving an error that the functions are not existing.

Does someknow how to do it by the right way?`

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions