Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

FakeDate does not accept a timestamp value #1069

Closed
EoinF opened this issue Apr 5, 2018 · 1 comment · Fixed by #1070
Closed

FakeDate does not accept a timestamp value #1069

EoinF opened this issue Apr 5, 2018 · 1 comment · Fixed by #1070

Comments

@EoinF
Copy link

EoinF commented Apr 5, 2018

Expected Behaviour: Passing a timestamp value into the Date object, as shown below, will produce a Date with that timestamp
Actual Behaviour: The timestamp is ignored and the current Date is used

In later versions (0.8.21 and onwards) this is happening, while using fakeAsync(worked with 0.8.20 and earlier)

The following code sample demonstrates this:

it('should set the right date', fakeAsync(() => {
    test();
    tick(1000);
    console.log("second", Date, new Date(0));
  }));

  async function test() {
    await (new Promise(resolve => {
      resolve();
    }));
    console.log("first", Date, new Date(0));
  }

The output is:

'first', function FakeDate() { ... }, Thu Apr 05 2018 11:05:19 GMT+0200 (CEST)
'second', function Date() { ... }, Thu Jan 01 1970 01:00:00 GMT+0100 (CET)

The first line of output is using the FakeDate object which is ignoring the value passed in and just producing the current Date.
The second line is working as expected.

This only occurs inside an async block, after an 'await' has been used

@JiaLiPassion
Copy link
Collaborator

JiaLiPassion commented Apr 5, 2018

@EoinF , thank you for posting the issue, I will try to fix this one.

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 5, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 5, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 5, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 5, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 5, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 5, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 5, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 6, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 6, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 6, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 6, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Apr 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants