MosheBerman / KosherCocoa

My Objective-C port of KosherJava. KosherCocoa enables you to perform sunrise-based and sunset-based calculations for Jewish prayer and calendar.
GNU Lesser General Public License v2.1
7 stars 3 forks source link

Bug in KCParashatHashavuaCalculator #8

Closed abmgames closed 9 years ago

abmgames commented 9 years ago

Hi first of all thanks for the amazing library There is a bug in KCParashatHashavuaCalculator The Parash jump one week forward from 4/07/2015 and crash on 12/09/2015

Thanks alot

MosheBerman commented 9 years ago

Hey, you're welcome! Glad you like it. Let's see if we can sort this out.

I have two thoughts on this:

1.Parasha is different in Israel and outside of Israel during some seasons of some years. Are you using the diaspora method or the Israel one?

  1. A crash in this class was reported in Issue #6, and I bet they're related. Do you have a crash log?

I have a few ideas about where this might be coming from, but code and a crash log would be helpful. Regardless, I'll take a look.

abmgames commented 9 years ago

Hi Great to hear from you so fast :-) I checked the location of the user , if outside Israel i'm using diaspora otherwise i'm using the Israel one. I manage to handle the crash and fix it till 2017 (but its temporary till we found the problem) The crash came from this method:

The problem is that the weeks jump foreword and go out of the parshiot nsarray range NSArray *parshiot = [self _parshiotForYearType:type inDiaspora:isInDiaspora];

/////------This what i write (quickly) to manage the bug till 2017
 //HOT FIX TILL JONE 2017
- (KCParasha *)_parashaForDate:(NSDate *)date inDiaspora:(BOOL)isInDiaspora
{

    date = [[self hebrewCalendar] lastDayOfTheWeekUsingReferenceDate:date];

    NSInteger year = [[self hebrewCalendar] yearsInDate:date];

    NSDate *roshHashana = [NSDate dateWithDay:1 Month:1 Year:year andCalendar:[self hebrewCalendar]];

    NSInteger weeksSinceRoshHashana = [[self hebrewCalendar] weeksFromDate:roshHashana toDate:date];

    kHebrewYearType type = [NSCalendar typeOfHebrewYearContainingDate:date];

    //
    //  Query the parshios
    //

    NSArray *parshiot = [self _parshiotForYearType:type inDiaspora:isInDiaspora];

    //
    //  Then look up this weeks parsha
    //

    //HOT FIX TILL JONE 2017
    BOOL isleap = NO;

    switch (type) {
        case kHebrewYearTypeH:
        case kHebrewYearTypeI:
        case kHebrewYearTypeJ:
        case kHebrewYearTypeK:
        case kHebrewYearTypeL:
        case kHebrewYearTypeM:
        case kHebrewYearTypeN:
            isleap = YES;
            break;
    }

    if (!isleap) {
        weeksSinceRoshHashana = weeksSinceRoshHashana > 39 ? weeksSinceRoshHashana - 1 : weeksSinceRoshHashana;
    }

    if (weeksSinceRoshHashana < [parshiot count]) {
        NSNumber *parashaIDNumber = parshiot[weeksSinceRoshHashana];

        enum KCParashaIdentifier parashaID = [parashaIDNumber integerValue];

        KCParasha *parasha = [KCParasha parashaWithIdentifier:parashaID];

        return parasha;
    }

    return nil;
}

Hope it will help you to figure out out go wrong Thanks alot

MosheBerman commented 9 years ago

Which parts of the method did you change? Also, can you please post a screenshot of the console when it crashes?

abmgames commented 9 years ago

I change only this part //HOT FIX TILL JONE 2017 BOOL isleap = NO;

switch (type) {
    case kHebrewYearTypeH:
    case kHebrewYearTypeI:
    case kHebrewYearTypeJ:
    case kHebrewYearTypeK:
    case kHebrewYearTypeL:
    case kHebrewYearTypeM:
    case kHebrewYearTypeN:
        isleap = YES;
        break;
}

if (!isleap) {
    weeksSinceRoshHashana = weeksSinceRoshHashana > 39 ? weeksSinceRoshHashana - 1 : weeksSinceRoshHashana;
}

if (weeksSinceRoshHashana < [parshiot count]) {
    NSNumber *parashaIDNumber = parshiot[weeksSinceRoshHashana];

    enum KCParashaIdentifier parashaID = [parashaIDNumber integerValue];

    KCParasha *parasha = [KCParasha parashaWithIdentifier:parashaID];

    return parasha;
}

return nil;
abmgames commented 9 years ago

This line make the crash NSNumber *parashaIDNumber = parshiot[weeksSinceRoshHashana]; weeksSinceRoshHashana going out of array bounds in the end of the year

isakvan commented 9 years ago

KCParashatHashavuaCalculator bug is fixed? :)

thanks

MosheBerman commented 9 years ago

Unfortunately, not yet. I'm interning at a company this summer, and I'm not working on third party code during that time, for copyright/intellectual property reasons.

If someone wants to look at the code and attempt a fix, I'll look at it - can't guarantee that I'll be able to accept a pull request.

My internship is over at the end of August.

isakvan commented 9 years ago

Moshe wish pass successfully. Get a good job and learn a lot of Torah!

MosheBerman commented 9 years ago

@abmgames Does PR #10 (36c66eb4a804e28a52d142932b1f0b4b31e7db32) fix the problem?

DanielSmith1239 commented 9 years ago

That fixed it for me. Thanks!

MosheBerman commented 9 years ago

Looks like that was the issue. Closing.