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

Yet more Date bugs... #133

Open
jsobell opened this issue May 2, 2018 · 11 comments
Open

Yet more Date bugs... #133

jsobell opened this issue May 2, 2018 · 11 comments

Comments

@jsobell
Copy link
Contributor

jsobell commented May 2, 2018

> var d=new Date()
undefined
> d
Wed May 02 2018 23:03:18 GMT+1000 (AUS Eastern Standard Time)
> d.setDate(3)
5
> d
Sat May 05 2018 23:03:18 GMT+1000 (AUS Eastern Standard Time)

Should be

> var d = new Date()
undefined
> d
Wed May 02 2018 23:03:36 GMT+1000 (Local Standard Time)
> d.setDate(3)
1525352616142
> d
Thu May 03 2018 23:03:36 GMT+1000 (Local Standard Time)
@jsobell
Copy link
Contributor Author

jsobell commented May 2, 2018

The current implementation adds the number of days supplied to the current value, while it should be adding those days-1 to the first day of the month of the current value.
Likewise with setUTCDate, and setUTCYear looks to be incorrectly implemented too.
https://www.w3schools.com/jsref/jsref_setdate.asp

Also, all of these functions should return the valueOf(), not the new month/date number.

All of this was working on the Date() version I sent you. I don't understand this obsession with reworking the javascript date handling into ticks and manually handling leap years etc.
PLEASE just take the code I sent you based on the DateTime object and fix anything you're not happy with, because hitting bugs again and again due to the complexity in your Date implementation is incredibly frustrating.
We have a demo to give on Friday, on nothing works because moment library fails again due to these bugs.

@jsobell
Copy link
Contributor Author

jsobell commented May 2, 2018

It's all fixed and working on my questmetrics branch at https://github.com/questmetrics/NiL.JS/tree/questmetrics

@jsobell
Copy link
Contributor Author

jsobell commented May 3, 2018

I've released a working version as a NuGet package for now, as we need it for our external build server. There were a number of other issues too related to whether UTC is assumed for different constructor types, and I added the Date(null) implementation and tests which fail on the current release.
Our fork of the project is called NiL.JS.QM

@nilproject nilproject reopened this May 3, 2018
@nilproject
Copy link
Owner

This bug caused by one misprint in line 212.
My implementation is complex and contains bugs, but with your implementation fails tests, which passed with my. In any case — still use my or use your implementation new fixes is needed. I want do add moment.js and tests for this framework as test suite for my engine. This should be done regardless of the implementation of Date.

@jsobell
Copy link
Contributor Author

jsobell commented May 3, 2018

The only tests that fail in my implementation are those involving things like
new Date(1970,1111111111111,1), which cause errors in .NET because they exceed the integer boundary.
Do we care about those edge cases, or more to the point, would people rather have everything else working correctly and those insanely huge functions be unavailable?
If you really want to have those tests pass, you could modify every date generation algorithm to look for insane size arguments and apply them in a loop to prevent overflows, but I really don't think it's worth it.
We have a range of regex expressions that also fail, but do we want to try and rework regex to fix that too? :)

jsobell added a commit to questmetrics/NiL.JS.QM that referenced this issue May 5, 2018
…ate `Sat Sep 13 275760 00:00:00 GMT+1000 (Local Standard Time)` (WTF?) pass.

Incorporated Fix nilproject#133 too
@jsobell
Copy link
Contributor Author

jsobell commented May 5, 2018

OK, it turns out there are loads of faults and some really weird requirements for some of the features such as addMonths(). I've added to my project a program that tests every function on a Date object and compares it to the same results from ClearScript.V8 (Chromium).
The Date class in my project now passes every single test, and supports assigning a CurrentTimezone.
Feel free to pull anything you like from there.

Bear in mind that you can't test the DST functionality because the Chromium interpreter used in the V8 library has a bug that gets the times wrong in some regions, so we have to stick to the DateTests.cs ones for those.
https://github.com/questmetrics/NiL.JS.QM

@jsobell
Copy link
Contributor Author

jsobell commented May 9, 2018

The only test I missed (so far) was setTime, and it was incorrectly adding timezone offset when it should be UTC only. It's fixed on mine, and I added a few moment and moment-timezone tests to my ClearScript comparer while I wasted 8 hours today trawling through moment and moment-timezone to work out why the fault only occurs on non-UTC servers...
https://github.com/nilproject/NiL.JS/blob/develop/NiL.JS/BaseLibrary/Date.cs#L499

@jsobell
Copy link
Contributor Author

jsobell commented May 29, 2018

We need these Date bugs fixing in the core.
Latest version still fails all of these tests in my test routines:

x   Difference: (new Date("2010-08-30T00:00:00")).valueOf(), 
  NiL=1283126400000 Mon Aug 30 2010 10:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1283090400000 Mon Aug 30 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).getUTCDate(), 
  NiL=30 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=29 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2010-08-30T00:00:00")).getUTCDay(), 
  NiL=1 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=0 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2010-08-30T00:00:00")).getUTCHours(), 
  NiL=0 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=14 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2010-08-30T00:00:00")).getYear(), 
  NiL=2010 Thu Jan 01 1970 11:00:02 GMT+1100 (AUS Eastern Summer Time)
   v8=110 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2010-08-30T00:00:00")).toISOString(), 
  NiL=2010-08-30T00:00:00.000Z 
   v8=2010-08-29T14:00:00.000Z 
x   Difference: (new Date("2010-08-30T00:00:00")).toJSON(), 
  NiL=2010-08-30T00:00:00.000Z 
   v8=2010-08-29T14:00:00.000Z 
x   Difference: (new Date("2010-08-30T00:00:00")).setMonth(5), 
  NiL=1277856000000 Wed Jun 30 2010 10:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1277820000000 Wed Jun 30 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setMilliseconds(555), 
  NiL=555 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=1283090400555 Mon Aug 30 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setFullYear(2005), 
  NiL=1125360000000 Tue Aug 30 2005 10:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1125324000000 Tue Aug 30 2005 00:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setMinutes(34), 
  NiL=34 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=1283092440000 Mon Aug 30 2010 00:34:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setTime(0), 
  NiL=-39600000 Thu Jan 01 1970 00:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=0 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setTime(1525898414436), 
  NiL=1525862414436 Wed May 09 2018 20:40:14 GMT+1000 (AUS Eastern Standard Time)
   v8=1525898414436 Thu May 10 2018 06:40:14 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setUTCMonth(5), 
  NiL=1277856000000 Wed Jun 30 2010 10:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1277820000000 Wed Jun 30 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setUTCMilliseconds(555), 
  NiL=555 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=1283090400555 Mon Aug 30 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setUTCHours(4), 
  NiL=1283104800000 Mon Aug 30 2010 04:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1283054400000 Sun Aug 29 2010 14:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setUTCFullYear(2004), 
  NiL=1093824000000 Mon Aug 30 2004 10:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1093788000000 Mon Aug 30 2004 00:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setUTCDate(15), 
  NiL=1281794400000 Sun Aug 15 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1281880800000 Mon Aug 16 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).setUTCMinutes(34), 
  NiL=34 Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=1283092440000 Mon Aug 30 2010 00:34:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00")).toLocaleDateString(), 
  NiL=Wednesday, 31 August 2011 
   v8=Mon Aug 30 2010 
x   Difference: (new Date("2010-08-30T00:00:00")).toLocaleTimeString(), 
  NiL=00:00:00 
   v8=00:00:00 GMT+1000 (AUS Eastern Standard Time) 
x   Difference: (new Date("2010-08-30T00:00:00")).toString(), 
  NiL=Mon Aug 30 2010 00:00:00 GMT0000 (AUS Eastern Standard Time) 
   v8=Mon Aug 30 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time) 
x   Difference: (new Date("2010-08-30T00:00:00")).toTimeString(), 
  NiL=00:00:00 GMT0000 (AUS Eastern Standard Time) 
   v8=00:00:00 GMT+1000 (AUS Eastern Standard Time) 

@nilproject
Copy link
Owner

nilproject commented May 30, 2018

Thanks! I fix it shortly.

nilproject added a commit that referenced this issue May 30, 2018
@jsobell
Copy link
Contributor Author

jsobell commented Jun 1, 2018

Still problems with the constructor:

x   Difference: (new Date("2010-08-30T00:00:00-0400")).valueOf(), 
  NiL=1283176800000 Tue Aug 31 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1283140800000 Mon Aug 30 2010 14:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2018-02-28T23:59:59Z")).valueOf(), 
  NiL=1519822799000 Wed Feb 28 2018 23:59:59 GMT+1100 (AUS Eastern Summer Time)
   v8=1519862399000 Thu Mar 01 2018 10:59:59 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2010-01-01Z")).valueOf(), 
  NiL=1262343600000 Fri Jan 01 2010 22:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=1262304000000 Fri Jan 01 2010 11:00:00 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2069-12-31T23:59:59Z")).valueOf(), 
  NiL=3155720399000 Tue Dec 31 2069 23:59:59 GMT+1100 (AUS Eastern Summer Time)
   v8=3155759999000 Wed Jan 01 2070 10:59:59 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("1970-04-30T23:55:00Z")).valueOf(), 
  NiL=10331700000 Thu Apr 30 1970 23:55:00 GMT+1000 (AUS Eastern Standard Time)
   v8=10367700000 Fri May 01 1970 09:55:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("1970-05-01T00:05:00Z")).valueOf(), 
  NiL=10332300000 Fri May 01 1970 00:05:00 GMT+1000 (AUS Eastern Standard Time)
   v8=10368300000 Fri May 01 1970 10:05:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2070-01-01T23:59:59Z")).valueOf(), 
  NiL=3155806799000 Wed Jan 01 2070 23:59:59 GMT+1100 (AUS Eastern Summer Time)
   v8=3155846399000 Thu Jan 02 2070 10:59:59 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2070-01-02T00:00:00Z")).valueOf(), 
  NiL=3155806800000 Thu Jan 02 2070 00:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=3155846400000 Thu Jan 02 2070 11:00:00 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2010-10-30T00:00:00Z")).valueOf(), 
  NiL=1288357200000 Sat Oct 30 2010 00:00:00 GMT+1100 (AUS Eastern Summer Time)
   v8=1288396800000 Sat Oct 30 2010 11:00:00 GMT+1100 (AUS Eastern Summer Time)
x   Difference: (new Date("2010-08-30T00:00:00-0400")).valueOf(), 
  NiL=1283176800000 Tue Aug 31 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1283140800000 Mon Aug 30 2010 14:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T01:02:03+0400")).valueOf(), 
  NiL=1283151723000 Mon Aug 30 2010 17:02:03 GMT+1000 (AUS Eastern Standard Time)
   v8=1283115723000 Mon Aug 30 2010 07:02:03 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00Z")).valueOf(), 
  NiL=1283090400000 Mon Aug 30 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1283126400000 Mon Aug 30 2010 10:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00+0000")).valueOf(), 
  NiL=1283162400000 Mon Aug 30 2010 20:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1283126400000 Mon Aug 30 2010 10:00:00 GMT+1000 (AUS Eastern Standard Time)
x   Difference: (new Date("2010-08-30T00:00:00+1000")).valueOf(), 
  NiL=1283126400000 Mon Aug 30 2010 10:00:00 GMT+1000 (AUS Eastern Standard Time)
   v8=1283090400000 Mon Aug 30 2010 00:00:00 GMT+1000 (AUS Eastern Standard Time)

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

No branches or pull requests

3 participants