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

DateTime creation in local time zone uses UTC instead if getting the local time zone offset causes an error #15560

Closed
alan-knight opened this issue Dec 10, 2013 · 14 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue core-a library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@alan-knight
Copy link
Contributor

We've occasionally seen flaking on Dartium on the round-trip date parsing tests where a date is printed one way and parsed back and the result fails. It seems that what's happening is that the resulting date is off from the desired one by the amount of a UTC correction. It particularly seems to happen on low information formats, e.g. just the month name or month and year. but that may just be coincidence.

An example failure is
Date mismatch!
  Expected 7
  Got 6
  Original date = 2012-07-27 13:58:59.012
  Original ms = 1343422739012
  Parsed back to 1970-06-30 17:00:00.000
  Parsed ms = 15638400000
  Original tz = -7:00:00.000000
  Current tz name =
  Current tz = -7:00:00.000000
  Current tz name =
  Start time = 2013-12-06 15:34:23.363
  Current time 2013-12-06 15:34:23.387
....
FAIL: Test round-trip parsing of dates
Expected: '7'
  Actual: '6'
   Which: is different.
Expected: 7
  Actual: 6
          ^
 Differ at offset 0

package:unittest/src/simple_configuration.dart 141:7 SimpleConfiguration.onExpectFailure
...
package:unittest/src/expect.dart 75:29 expect
../../../../root_dart/pkg/intl/test/date_time_format_test_core.dart 188:13 testRoundTripParsing
../../../../root_dart/pkg/intl/test/date_time_format_test_core.dart 261:29 runDateTests.<fn>

@anders-sandholm
Copy link
Contributor

Added Area-Library label.

@lrhn
Copy link
Member

lrhn commented Jan 22, 2014

Removed Library-Core, Area-Library labels.
Added Area-Pkg label.

@anders-sandholm
Copy link
Contributor

Removed Library-Intl label.
Added Pkg-Intl label.

@alan-knight
Copy link
Contributor Author

After adding a lot of logging for this I saw the problem in a log on Friday.
http://chromegw.corp.google.com/i/client.dart/builders/dartium-lucid64-full-be/builds/2661/steps/dartium_core_unchecked_tests/logs/stdio

The log is very long, as there's lots of debug code around that now, but the relevant portion seems to be
Creating Date from
                        UTC: false
                        year: 1970
                        month: 1
                        day: 1
                        pm: false
                        hour: 0
                        minute: 58
                        second: 59
                        fractionalSecond: 0
                    Created 1970-01-01 00:58:59.000
Creating Date from
                        UTC: false
                        year: 1970
                        month: 1
                        day: 1
                        pm: false
                        hour: 0
                        minute: 0
                        second: 0
                        fractionalSecond: 0
                    Created 1969-12-31 16:00:00.000

which comes from date_format_helpers.dart lines 42-78.

So we're calling new DateTime and in one case it's producing the desired date and in the other it's applying UTC correction even though it wasn't asked for. So either the VM is doing something odd in there or the DateTime code is.


cc @kevmoo.
Removed Area-Pkg, Pkg-Intl labels.
Added Area-Library label.

@kevmoo
Copy link
Member

kevmoo commented May 12, 2014

Added Library-Core label.

@alan-knight
Copy link
Contributor Author

Florian writes:
Since the output doesn't contain a "Z" at the end we know that the generated DateTime is not a UTC date-time. This means that it did take the right branch and that it did invoke the right constructor. This means that the most likely culprit is the function that gets the timezone offset: _localTimeZonAdjustmentInSeconds (in runtime/lib/date_patch.dart).
That one dispatches to OS::GetTimeZonOffsetInSeconds (runtime/vm/os_linux.cc) with the following code:
===
  tm decomposed;
  bool succeeded = LocalTime(seconds_since_epoch, &decomposed);
  // Even if the offset was 24 hours it would still easily fit into 32 bits.
  // If unsuccessful, return zero like V8 does.
  return succeeded ? static_cast<int>(decomposed.tm_gmtoff) : 0;
===

So it looks like succeeded was false and we just returned "0".
We have a few options now:

  • add debug-logging to that function and figure out why it fails.
  • add a loop to retry when it fails.
  • throw when it doesn't succeed, instead of silently return 0.
    cc @fsc8000.
    cc @lrhn.
    cc @skabet.
    Removed the owner.

@andersjohnsen
Copy link

The fact that we see this, and V8 doesn't, is that because we test it better then they do?

@floitschG
Copy link
Contributor

There could be several reasons.

  • better test coverage (we don't see it in our non-package tests either)
  • different setup. Dart calls tzset much more often.
  • different test-server. I have never seen this test fail locally so far.

@alan-knight
Copy link
Contributor Author

Are we going to do anything about this? This causes flakiness in the DateTime tests. I suppose I can change its date creation to create the date three times and go with the majority opinion, but that doesn't seem elegant.


Changed the title to: "DateTime creation in local time zone uses UTC instead if getting the local time zone offset causes an error".

@andersjohnsen
Copy link

I wonder if the call to 'localtime_r' can fail with E_INTR. We could try to check for it, and call again while errno == E_INTR.

@alan-knight
Copy link
Contributor Author

Issue #19916 has been merged into this issue.


cc @vsmenon.

@alan-knight
Copy link
Contributor Author

https://codereview.chromium.org/399973002 has an additional workaround for this in the Intl tests.

@alan-knight alan-knight added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core labels Jul 17, 2014
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@lrhn lrhn added the core-a label Aug 11, 2017
@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 19, 2018
@alan-knight
Copy link
Contributor Author

Not stale. Still happens.

@alan-knight alan-knight reopened this Jun 19, 2018
@lrhn lrhn removed the closed-obsolete Closed as the reported issue is no longer relevant label Jun 21, 2018
@lrhn
Copy link
Member

lrhn commented Nov 10, 2021

We are, however, still not fixing it.

@lrhn lrhn closed this as completed Nov 10, 2021
@lrhn lrhn added the closed-not-planned Closed as we don't intend to take action on the reported issue label Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue core-a library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants