GithubHelp home page GithubHelp logo

Comments (1)

percysnoodle avatar percysnoodle commented on July 17, 2024

Looking further into this, it also affects 2011 and 2012, but not 2009 or 2008. Not sure what makes them different.

I notice there's a comment in the code:

    // -[NSDateComponents weekOfYear] doesn't explicitly specify what its valid range is. In the Gregorian case, it appears to be [1,52], which means the last day of December is probably going to be week 1 of next year. The same logic extends to other calendars.

so I added this code to -[tableView:numberOfRowsInSection:] to test out the range methods on NSCalendar:

    if ((section == 480) || (section == 504))
    {
        NSLog(@"section %d", section);
        NSLog(@"firstWeek %d", firstWeek);
        NSLog(@"nextToLastWeek %d", nextToLastWeek);
        NSRange range;

        range = [self.calendar minimumRangeOfUnit:NSWeekOfYearCalendarUnit];
        NSLog(@"minimumRangeOfUnit:[%d, %d]", range.location, range.location + range.length - 1);

        range = [self.calendar maximumRangeOfUnit:NSWeekOfYearCalendarUnit];
        NSLog(@"maximumRangeOfUnit:[%d, %d]", range.location, range.location + range.length - 1);

        range = [self.calendar rangeOfUnit:NSWeekOfYearCalendarUnit inUnit:NSYearCalendarUnit forDate:firstOfMonth];
        NSLog(@"rangeOfUnit:inUnit:[%d, %d]", range.location, range.location + range.length - 1);
    }

I got this output:

2013-03-16 18:42:31.324 MyApp[95353:c07] section 480
2013-03-16 18:42:31.324 MyApp[95353:c07] firstWeek 53
2013-03-16 18:42:31.324 MyApp[95353:c07] nextToLastWeek 3
2013-03-16 18:42:31.324 MyApp[95353:c07] minimumRangeOfUnit:[1, 52]
2013-03-16 18:42:31.324 MyApp[95353:c07] maximumRangeOfUnit:[1, 53]
2013-03-16 18:42:31.324 MyApp[95353:c07] rangeOfUnit:inUnit:[0, 52]
2013-03-16 18:42:31.325 MyApp[95353:c07] section 504
2013-03-16 18:42:31.326 MyApp[95353:c07] firstWeek 52
2013-03-16 18:42:31.326 MyApp[95353:c07] nextToLastWeek 4
2013-03-16 18:42:31.326 MyApp[95353:c07] minimumRangeOfUnit:[1, 52]
2013-03-16 18:42:31.326 MyApp[95353:c07] maximumRangeOfUnit:[1, 53]
2013-03-16 18:42:31.326 MyApp[95353:c07] rangeOfUnit:inUnit:[0, 53]

Hopefully that's useful in figuring out the valid range. I also found that I can work around the problem by adding this just before the return:

    if (firstWeek > nextToLastWeek)
    {
        // The first week must have been the end of last year.
        firstWeek = 0;
    }

but I'm not sure I understand what I've done well enough to say that that's fixed the problem. I could still put it in a pull request, if you'd like (I've signed the CLA for KIF - do I need to sign it again for TS?).

from objc-timessquare.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.