Conversation
…t explicitly by "+ (void)mt_setFirstDayOfWeek:(NSUInteger)firstDay" or implicitly by locale)
MTDatesTests/MTDatesTests.m
Outdated
There was a problem hiding this comment.
Have you tried to run unit tests locally? I don't think they pass to you. At least I can't figure out how unit tests can pass locally to you...
This probably should be XCTAssertEqualObjects. That's why the build on TravisCI has been failed...
|
Yup sorry... Did another commit... |
|
Oh man... I use this code in my app but didnt use the test for a while... Have to check later again... |
da048ea to
6c7b846
Compare
|
I'm not sure this it actually real problem in the MTDates. I can suppose that the added unit test can give false-positive feedback because you are changing first day of week only in the calendar used by MTDates internally... The current implementations of And even more, which is more important. I've just tried to use the version of MTDates with this fix and I see failing unit tests of my app!! context(@"when week starts from Monday", ^{
it(@"sets correct weekday", ^{
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
calendar.firstWeekday = 2;
[NSCalendar stub:@selector(currentCalendar) andReturn:calendar];
[NSDate mt_setFirstDayOfWeek:2]; // Monday
event.startsAt = [NSDate mt_dateFromYear:2012 month:8 day:7]; // trigger recurrence rule update
[[event.recurrenceRule[@"weekday"] should] equal:@"tuesday"];
[NSDate mt_setFirstDayOfWeek:0]; // To reset to default value
});
});@atomkirk this patch doesn't seem to be correct to me. |
|
You may be right. |
|
@Alex9779 thank you! The dates are hard))) I'm not 100% sure I'm right, but at least I see a failing test in my production app with the patch. sorry... |
|
Np. |
|
Ok I ran the test now locally. Try running the test I created with and without the patch. |
|
Here is my test output without the fix: |
|
@Alex9779 looks like I'm starting to understand the issue you are fixing :) However I'm not completely understand why one of the tests in my production code fails with the fix... Maybe I have a bug somewhere? ;) I'll double check it later. So can we say then that Here is the test explaining this case I'd like to propose to include as well: - (void)test_weekdayOfWeekRemainsTheSameInSpiteOfFirstDayOfAWeek
{
NSDate *date = [_formatter dateFromString:@"10/09/2014 05:00am"]; // Thursday
[NSDate mt_setFirstDayOfWeek:1];
XCTAssertEqual([date mt_weekdayOfWeek], 5);
[NSDate mt_setFirstDayOfWeek:2];
XCTAssertEqual([date mt_weekdayOfWeek], 5);
[NSDate mt_setFirstDayOfWeek:3];
XCTAssertEqual([date mt_weekdayOfWeek], 5);
[NSDate mt_setFirstDayOfWeek:4];
XCTAssertEqual([date mt_weekdayOfWeek], 5);
[NSDate mt_setFirstDayOfWeek:5];
XCTAssertEqual([date mt_weekdayOfWeek], 5);
[NSDate mt_setFirstDayOfWeek:6];
XCTAssertEqual([date mt_weekdayOfWeek], 5);
[NSDate mt_setFirstDayOfWeek:7];
XCTAssertEqual([date mt_weekdayOfWeek], 5);
}Does this sounds right to you? Actually exactly this test shows a regression in I've fixed it by adding And also seems reasonable to improve Give me a few minutes and I'll push what I have :) |
|
Now I remember the real problem I had, took a bit but your explanation posted it out to me again. The method you use to GET the weekday always returns the weekday based on 1=sunday no matter what your start of the week is set to. So whatever calendar you use if you wanna GET the weekday of a date it is always right. |
|
Oh and well, my fix fixed my problem, to be able to calculate a date in the future with a given interval but to be a specific weekday. |
|
@Alex9779 you definitely did a great work pointing it out! Looks like it doesn't cover all the cases and maybe event introduces some regressions, but don't worry: I'm almost done with the remaining fixes!! Will open pull request (including your commits) very soon :) |
|
@Alex9779 please take a look at #49. I thought I fixed the problems not covered here, but now I see a lot more failing tests inside of my app. Too tired now and stopping at current point. Would be great if you could review and test my pull review as well. Thanks in advance! Thanks for all your work on this! |
|
Closing for #49 to continue what started here... |

New pull request for previously closed one...