Test `twitter.test.js` not passing
GauBen opened this issue · comments
Hello, I noticed that a test is not passing:
1) style/twitter
should format Twitter style relative time (English) (absolute dates):
AssertionError: expected 'Dec 9' to equal 'Dec 10'
+ expected - actual
-Dec 9
+Dec 10
at Context.equal (source/style/twitter.test.js:72:43)
at processImmediate (node:internal/timers:464:21)
The issue could be somehow related to time zones.
The test creates a date:
new Date(2016, 3, 10, 12, 0)
The date is gonna be at 12:00 in the current user's time zone.
When I'm running it, it's a date corresponding to 12:00 in Moscow.
When you're running it, it's a date corresponding to 12:00 in France.
But, at the same time, the date formatter used in twitter
style format should also format the date in the same time zone, so it shouldn't be an issue:
var d = new Date(2016, 3, 10, 12, 0)
console.log(d)
// Outputs: Sun Apr 10 2016 12:00:00 GMT+0300 (Moscow Standard Time)
var f = new Intl.DateTimeFormat('en', {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric'
})
console.log(f.format(a))
// Outputs: "Apr 10, 12:00 PM"
So, regardless from the user's time zone, it should output the same results.
But in your case it outputs Dec 9
instead of Dec 10
.
That's weird.
That shouldn't be possible.
Another thing is that month * 8
is 243.52 and there are 244 days between Apr 10th and Dec 10th
formatDatePastBy(-243.55 * 24 * 60 * 60).should.equal('Dec 10') // Passes
formatDatePastBy(-243.54 * 24 * 60 * 60).should.equal('Dec 10') // Fails