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

mt_dateFromYear:week:weekday returns unexpected values #8

Open
averydev opened this issue Dec 29, 2014 · 3 comments
Open

mt_dateFromYear:week:weekday returns unexpected values #8

averydev opened this issue Dec 29, 2014 · 3 comments

Comments

@averydev
Copy link

I happened to notice, because it's the 28th of December, but there is something odd happening with the week number of the year. Specifically it seems to think that this week is week 1:

    NSDate *testDate = [NSDate mt_startOfToday];
    NSLog(@"Checking week of year = %ld",[testDate mt_weekOfYear]);
//Output: Checking week of year = 1

Some other related oddities
[NSDate mt_dateFromYear:2014 week:1 weekday:1] returns 12/28/14
[NSDate mt_dateFromYear:2014 week:2 weekday:1] returns 1/5/14 This is as I would expect it.

[NSDate mt_dateFromYear:2014 week:1 weekday:6] returns 1/2/15 which is pretty wild.

I haven't gotten a chance to dig in and see what's going on, but figure'd I would start off and post an issue.

Thanks for the great library, it's a lifesaver!

@pwightman
Copy link
Member

Twitter went down yesterday for a related issue (their servers thought it was 2015, so all oauth tokens were invalidated and couldn't be renewed). Very interesting.

@averydev
Copy link
Author

I still haven’t gotten a chance to look at what is causing this, and though it’s possible that it is something deep in date management, but I think it's unlikely because I am getting correct dates when I add 7 days, but not when I add 1 week (or anything relating to weeks).

While poking around I noticed that for instance mt_oneWeekNext does this

- (NSDate *)mt_oneWeekNext
{
    [[NSDate sharedRecursiveLock] lock];
    NSDate *date = [self mt_dateByAddingYears:0 months:0 weeks:1 days:0 hours:0 minutes:0 seconds:0];
    [[NSDate sharedRecursiveLock] unlock];
    return date;
}

But then,

- (NSDate *)mt_dateByAddingYears:(NSInteger)years months:(NSInteger)months weeks:(NSInteger)weeks days:(NSInteger)days hours:(NSInteger)hours minutes:(NSInteger)minutes seconds:(NSInteger)seconds

In the weeks component uses:

   if (weeks)      [comps setWeekOfYear:weeks];

setWeekOfYear looks different than for instance [comps setMonth:months] in that it's naming is a different pattern so might work differently.

It's possible that this is just a weeks problem, not a date problem generally. To add weeks, it's possible that one would need to use weeks * daysInWeek + days in the days component rather than set the weekOfYear directly.

When I'm done with my current deadline I'd be happy to take a deeper look, I just noticed this in passing.

@atomkirk
Copy link
Member

As a hint, the problem is most likely gonna be in the MTDates library, not the MTPDF lib

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

No branches or pull requests

3 participants