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

getTimezoneOffset should not round #33306

Closed
SheetJSDev opened this issue May 8, 2020 · 2 comments
Closed

getTimezoneOffset should not round #33306

SheetJSDev opened this issue May 8, 2020 · 2 comments
Labels
v8 engine Issues and PRs related to the V8 dependency.

Comments

@SheetJSDev
Copy link
Contributor

SheetJSDev commented May 8, 2020

  • Version: 14.2.0
  • Platform: darwin
  • Subsystem:

What steps will reproduce the bug?

Run NodeJS REPL in the Asia/Hong_Kong timezone (TZ=Asia/Hong_Kong node) and run

var d=new Date(1899, 11, 30, 0, 0, 0);
console.log(d.getTimezoneOffset())

How often does it reproduce? Is there a required condition?

Always reproduces

What is the expected behavior?

According to https://www.timeanddate.com/time/zone/hong-kong/hong-kong (look at the Time zone changes for: 1850-1899) the timezone was +7:36:42 which would suggest the timezone offset should be -456.7, potentially with a sub-second difference

In case you need an "official" listing, the IANA tz database lists the following for Asia/Hong_Kong:

# Zone	NAME		STDOFF	RULES	FORMAT	[UNTIL]
Zone	Asia/Hong_Kong	7:36:42 -	LMT	1904 Oct 30  0:36:42

So it definitely has a sub-minute component

What do you see instead?

-456 it appears NodeJS is rounding.

According to the spec https://tc39.es/ecma262/#sec-date.prototype.gettimezoneoffset

Return (t - LocalTime(t)) / msPerMinute.

That division is not integer division. Other date functions which do require integer results are explicitly specced with an appropriate integer operation.

Additional information

This also affects Chrome, so this is probably a v8 bug.

Related issues:

@heroboy
Copy link

heroboy commented May 8, 2020

@bnoordhuis
Copy link
Member

I was just about to link to that issue. :-)

The relevant code in V8 is this:

if (index == kTimezoneOffset) {
GetIsolate()->CountUsage(v8::Isolate::kDateGetTimezoneOffset);
return Smi::FromInt(date_cache->TimezoneOffset(time_ms));
}

int TimezoneOffset(int64_t time_ms) {
int64_t local_ms = ToLocal(time_ms);
return static_cast<int>((time_ms - local_ms) / kMsPerMin);
}

Which operates on ints, not doubles. I'll close this out because it's ultimately not a Node.js issue but we can cherry-pick upstream fixes once they materialize. Thanks anyway for the bug report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

3 participants