Skip to content

this.setUTCTime is not a function #13

Open
@byTimo

Description

@byTimo

After installing the package I got date/mini.js with the following content

export class UTCDateMini extends Date {
  constructor() {
    super();
    this.setTime(arguments.length === 0 ?
    // Enables Sinon's fake timers that override the constructor
    Date.now() : arguments.length === 1 ? typeof arguments[0] === "string" ? +new Date(arguments[0]) : arguments[0] : Date.UTC(...arguments));
  }
  getTimezoneOffset() {
    return 0;
  }
  getDate(){return this.getUTCDate();}
  setDate(){return this.setUTCDate();}
  getDay(){return this.getUTCDay();}
  getFullYear(){return this.getUTCFullYear();}
  setFullYear(){return this.setUTCFullYear();}
  getHours(){return this.getUTCHours();}
  setHours(){return this.setUTCHours();}
  getMilliseconds(){return this.getUTCMilliseconds();}
  setMilliseconds(){return this.setUTCMilliseconds();}
  getMinutes(){return this.getUTCMinutes();}
  setMinutes(){return this.setUTCMinutes();}
  getMonth(){return this.getUTCMonth();}
  setMonth(){return this.setUTCMonth();}
  getSeconds(){return this.getUTCSeconds();}
  setSeconds(){return this.setUTCSeconds();}
  getTime(){return this.getUTCTime();}
  setTime(){return this.setUTCTime();}
  getYear(){return this.getUTCYear();}
  setYear() {return this.setUTCYear();}
}

The problem is Date doesn't have methods

this.getUTCTime()
this.setUTCTime()
this.getUTCYear()
this.setUTCYear()

And since setTime called in the constructor, the following error happens in browser

dev.js:1102 Uncaught TypeError: this.setUTCTime is not a function
    at UTCDate.setTime (mini.js:27:25)
    at new UTCDateMini (mini.js:4:10)
    at new UTCDate (index.js:16:8)
    at parse (date.ts:7:63)

which make the lib completely unusable.
I have no idea what produces this code.

I'm using Typescript with "module": "NodeNext" and "moduleResolution": "NodeNext". The version of @date-fns/utc is 2.1.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions