-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Modifies all dates in the calendar to have their time set to noon #114
Modifies all dates in the calendar to have their time set to noon #114
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but, tests? ༼ つ ◕_◕ ༽つ
WAIT I GET IT. So the general idea is that we were setting the utc offset like so: I am mostly writing this down so that years down the line we'll have a record of this. |
39b2b92
to
6b8cb0b
Compare
just kidding, thanks for making me write tests @ljharb. The original code didn't actually do what I expected. :) This should fix things. PTAL! |
@@ -20,6 +20,10 @@ describe('toMomentObject', () => { | |||
expect(toMomentObject()).to.equal(null); | |||
}); | |||
|
|||
it('output has time of 12PM', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be nice to test the actual conditions - like, that the thing resulting in the extra day being highlighted returns the correct result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This becomes a bit harder to test I think because it... depends on a lot of different factors. I mean, I guess we can check that the first of april/last of march and first of march/last of april do not make isSameDay true but that seems like a bad test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would test the actual bug this had reported, and assuming the dates were somewhat hardcoded, would likely prevent a regression. Changing the times to 12:01, for example, shouldn't fail tests, because it wouldn't trigger the underlying bug.
Hey @majapw, I was just fiddling with the code here and I think I've found a simple (and reliable) solution for this problem. First of all, the So, I think that if you do the reverse process when using the day, you'll be "safe". In this case, there are just three simple changes. The first is in // old
const prevDay = enableOutsideDays && currentDay.clone().subtract(i + 1, 'day');
// new
const prevDay = enableOutsideDays && currentDay.clone().subtract(i + 1, 'day').local(); The second is in // old
currentWeek.push(currentDay.clone());
// new
currentWeek.push(currentDay.clone().local()); And the third in // old
const nextDay = enableOutsideDays && currentDay.clone().add(count, 'day');
// new
const nextDay = enableOutsideDays && currentDay.clone().add(count, 'day').local(); What do you think about that @majapw? More about |
Does that actually still solve the DST issue @wmartins? I kind of feel like the setting the time to the middle of the day is still a bit safer and a bit simpler. |
I would need to test a little bit more to confirm more cases, but if you Just investigated the issue a little bit and brought this alternative Em qua, 12 de out de 2016 12:28, Maja Wichrowska [email protected]
|
5a24720
to
387e62c
Compare
@ljharb I added some tests that I confirmed used to fail (with the utcOffset) and now pass. Can you PTAL and then we can get this bad boy merged in. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Only nonblocker comments.
describe('Daylight Savings Time issues', () => { | ||
it('last of February does not equal first of March', () => { | ||
const february = getCalendarMonthWeeks(today.clone().month(1)); | ||
const lastWeekOfFebruary = february[february.length - 1].filter(day => !!day); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw .filter(Boolean)
works here too :-)
const lastOfFebruary = lastWeekOfFebruary[lastWeekOfFebruary.length - 1]; | ||
|
||
const march = getCalendarMonthWeeks(today.clone().month(2)); | ||
const firstOfMarch = march[0].filter(day => !!day)[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably use .find(Boolean)
instead
387e62c
to
1f1c5d0
Compare
Awesome! I fixed the tests that were breaking as a result of changing the date's time. :) So we should be set now. Will merge in after tests pass. |
This is a fix for #110
I also double-checked this change in the Brazilian time zone and noted that there is no reoccurrence of the DST bug that caused there to be an extra day in the month of October. It might be good to double-check Australia as well.
I'm not like incredibly happy about this, but it seems to work. :|
to: @timReynolds @ljharb
FYI: @airbnb/webinfra @wmartins