Ejemplo n.º 1
0
 public BadiDate(int year, int month, int days, RelationToMidnight relationToMidnight)
 {
     Year  = year;
     Month = month;
     Day   = days;
     RelationToMidnight = relationToMidnight;
 }
Ejemplo n.º 2
0
 public void GetGregorianDate_AroundJan1(int bYear, int bMonth, int bDay, RelationToMidnight relationToMidnight, int gYear, int gMonth, int gDay)
 {
     _badi.GetGregorianDate(bYear, bMonth, bDay, relationToMidnight).ShouldBeSameDayAs(new DateTime(gYear, gMonth, gDay));
 }
Ejemplo n.º 3
0
 public void GetBadiDate_AfterNawRuz(int gYear, int gMonth, int gDay, RelationToSunset relationToSunset, int bYear,
                                     int bMonth, int bDay, RelationToMidnight relationToMidnight)
 {
     _badi.GetBadiDate(new DateTime(gYear, gMonth, gDay), relationToSunset)
     .ShouldBe(new BadiDate(bYear, bMonth, bDay, relationToMidnight));
 }
Ejemplo n.º 4
0
        public DateTime GetGregorianDate(int bYear, int bMonth, int bDay, RelationToMidnight relationToMidnight = RelationToMidnight.bDay_BeforeSunset_Frag2,
                                         bool autoFix = false)
        {
            if (bMonth < 0)
            {
                if (autoFix)
                {
                    bMonth = 1;
                }
                else
                {
                    throw new ApplicationException("Invalid Badi month: " + bMonth);
                }
            }

            if (bMonth > 19)
            {
                if (autoFix)
                {
                    bMonth = 19;
                }
                else
                {
                    throw new ApplicationException("Invalid Badi month: " + bMonth);
                }
            }

            if (bDay < 1)
            {
                if (autoFix)
                {
                    bDay = 1;
                }
                else
                {
                    throw new ApplicationException("Invalid Badi day: " + bDay);
                }
            }
            if (bDay > 19)
            {
                if (autoFix)
                {
                    bDay = 19;
                }
                else
                {
                    throw new ApplicationException("Invalid Badi day: " + bDay);
                }
            }

            DateTime answer;

            var gYear = bYear + 1843;

            switch (bMonth)
            {
            case 0:
                var numDaysInAyyamiHa = DaysInAyyamiHa(bYear);
                if (bDay > numDaysInAyyamiHa)
                {
                    if (autoFix)
                    {
                        bDay = numDaysInAyyamiHa;
                    }
                    else
                    {
                        throw new ApplicationException("Invalid day for Ayyam-i-Ha: " + bDay);
                    }
                }
                answer = GetGregorianDate(bYear, 18, 19).AddDays(bDay);

                break;

            case 19:
                var nextNawRuz          = GetNawRuz(gYear + 1, true);
                var firstDayOfLoftiness = nextNawRuz.AddDays(-19);

                answer = firstDayOfLoftiness.AddDays(bDay - 1);
                break;

            default:
                var nawRuz = GetNawRuz(gYear, true);
                //var beforeMidnightOffset = relationToMidnight == RelationToMidnight.bDay_BeforeSunset_Frag2 ? 1 : 0;
                answer = nawRuz.AddDays((bMonth - 1) * 19 + bDay - 1);
                break;
            }

            // if calcuating sunset, get sunset for this date!
            if (relationToMidnight == RelationToMidnight.bEvePrior_AfterSunset_Frag1)
            {
                answer = answer.AddDays(-1);
            }

            return(answer);
        }