Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.setUTCTime is not a function #13

Open
byTimo opened this issue Jan 31, 2025 · 0 comments
Open

this.setUTCTime is not a function #13

byTimo opened this issue Jan 31, 2025 · 0 comments

Comments

@byTimo
Copy link

byTimo commented Jan 31, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant