Пример #1
0
        // test if today is tithi of given masa, or day after tithi of given masa
        // while in second cas yesterday is tithi before given tithi and masa
        public bool testFestival(GCFestivalSpecialExecutor exec, bool stickToMasa)
        {
            VAISNAVADAY yesterday = exec.day(-DayOffset - 1);
            VAISNAVADAY today     = exec.day(-DayOffset);
            VAISNAVADAY tomorrow  = exec.day(-DayOffset + 1);

            if (today.astrodata.Masa == nMasa && today.astrodata.sunRise.Tithi == nTithi)
            {
                if (yesterday.astrodata.Masa == nMasa && yesterday.astrodata.sunRise.Tithi == nTithi)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            if (stickToMasa || GCMasa.IS_EXTRA(today.astrodata.Masa))
            {
                if (today.ksayaMasa == nMasa && today.ksayaTithi == nTithi)
                {
                    return(true);
                }
            }
            else
            {
                if (yesterday.ksayaMasa == nMasa && yesterday.ksayaTithi == nTithi)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        public int AddMatchedFestivals(GCFestivalSpecialExecutor exec)
        {
            int currFestTop = 0;

            for (int i = BEFORE_DAYS; i < m_PureCount + BEFORE_DAYS - 1; i++)
            {
                exec.CurrentIndex = i;
                foreach (GCFestivalBook book in GCFestivalBookCollection.Books)
                {
                    if (!book.Visible)
                    {
                        continue;
                    }

                    foreach (GCFestivalBase fb in book.Festivals)
                    {
                        if (fb.nReserved == 1 && fb.nVisible > 0 && fb.IsFestivalDay(exec))
                        {
                            currFestTop = AddEventToDay(exec, 0, currFestTop, fb);
                        }
                    }
                }
            }

            return(1);
        }
Пример #3
0
        public override bool IsFestivalDay(GCFestivalSpecialExecutor exec)
        {
            VAISNAVADAY t = exec.day(-DayOffset);

            if (nMasaMin <= nMasaMax)
            {
                if (t.astrodata.Masa < nMasaMin || t.astrodata.Masa > nMasaMax)
                {
                    return(false);
                }
            }
            else
            {
                if (t.astrodata.Masa < nMasaMin && t.astrodata.Masa > nMasaMax)
                {
                    return(false);
                }
            }

            GSCore c = exec.ExecuteElement(script);

            if (c is GSReturn)
            {
                bool retval = c.getBooleanValue();
                return(retval);
            }

            return(false);
        }
Пример #4
0
        public override bool IsFestivalDay(GCFestivalSpecialExecutor exec)
        {
            VAISNAVADAY testDay = exec.day(-DayOffset);

            return(testDay.astrodata.Masa == nMasa &&
                   testDay.astrodata.sunRise.Paksa == nPaksa &&
                   (GCTithi.TITHI_EKADASI(testDay.astrodata.sunRise.Tithi) ||
                    GCTithi.TITHI_DVADASI(testDay.astrodata.sunRise.Tithi)) &&
                   testDay.nFastID == FastType.FAST_EKADASI);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="exec"></param>
        /// <param name="offsetWithToday">If value of this parameter is 0, then current day is processed,
        /// -1 is for yesterday, +1 is for tomorrow</param>
        /// <param name="currFestTop"></param>
        /// <param name="fb"></param>
        /// <returns></returns>
        private int AddEventToDay(GCFestivalSpecialExecutor exec, int offsetWithToday, int currFestTop, GCFestivalBase fb)
        {
            VAISNAVADAY   t  = exec.day(offsetWithToday);
            VAISNAVAEVENT md = t.AddEvent(DisplayPriorities.PRIO_FESTIVALS_0 + fb.BookID * 100 + currFestTop,
                                          GCDS.CAL_FEST_0 + fb.BookID, fb.Text);

            currFestTop += 5;
            if (fb.FastID > 0)
            {
                md.fasttype    = fb.FastID;
                md.fastsubject = fb.FastingSubject;
            }

            if (GCDisplaySettings.Current.getValue(51) != 2 && fb.StartYear > -7000)
            {
                String ss1;
                int    years = t.astrodata.GaurabdaYear - (fb.StartYear - 1496);
                string appx  = "th";
                if (years % 10 == 1)
                {
                    appx = "st";
                }
                else if (years % 10 == 2)
                {
                    appx = "nd";
                }
                else if (years % 10 == 3)
                {
                    appx = "rd";
                }
                if (GCDisplaySettings.Current.getValue(51) == 0)
                {
                    ss1 = string.Format("{0} ({1}{2} anniversary)", md.text, years, appx);
                }
                else
                {
                    ss1 = string.Format("{0} ({1}{2})", md.text, years, appx);
                }
                md.text = ss1;
            }

            if (fb.EventsCount > 0)
            {
                foreach (GCFestivalBase re in fb.Events)
                {
                    if (re is GCFestivalRelated)
                    {
                        GCFestivalRelated related = re as GCFestivalRelated;
                        AddEventToDay(exec, fb.DayOffset + related.DayOffset, 0, related);
                    }
                }
            }

            return(currFestTop);
        }
        // test if today is tithi of given masa, or day after tithi of given masa
        // while in second cas yesterday is tithi before given tithi and masa
        public bool testFestival(GCFestivalSpecialExecutor exec, bool stickToMasa)
        {
            VAISNAVADAY yesterday = exec.day(-DayOffset - 1);
            VAISNAVADAY today     = exec.day(-DayOffset);
            VAISNAVADAY tomorrow  = exec.day(-DayOffset + 1);

            if (today.astrodata.Masa == nMasa && today.astrodata.sunRise.Tithi == nTithi)
            {
                if (yesterday.astrodata.Masa == nMasa && yesterday.astrodata.sunRise.Tithi == nTithi)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            // in case tithi is ksaya, and we want to observe festival on the calendar day, when tithi is ksaya, return yes
            if (today.ksayaMasa == nMasa && today.ksayaTithi == nTithi && GCDisplaySettings.Current.AdvFestivalFirstDay)
            {
                return(true);
            }

            if (stickToMasa || GCMasa.IS_EXTRA(today.astrodata.Masa))
            {
                if (today.ksayaMasa == nMasa && today.ksayaTithi == nTithi)
                {
                    return(true);
                }
            }
            else
            {
                if (yesterday.ksayaMasa == nMasa && yesterday.ksayaTithi == nTithi && GCDisplaySettings.Current.AdvFestivalFirstDay == false)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #7
0
        /// <summary>
        /// Main function for CALENDAR calculations
        /// </summary>
        /// <param name="loc"></param>
        /// <param name="begDate"></param>
        /// <param name="iCount"></param>
        /// <returns></returns>
        public int CalculateCalendar(GCLocation loc, GregorianDateTime begDate, int iCount)
        {
            int i, weekday;
            int nTotalCount = BEFORE_DAYS + iCount + BEFORE_DAYS;
            GregorianDateTime date;
            GCEarthData       earth;
            int    lastMasa  = 0;
            int    lastGYear = 0;
            String tempStr;
            bool   bCalcMoon = (GCDisplaySettings.Current.getValue(4) > 0 || GCDisplaySettings.Current.getValue(5) > 0);

            m_nCount   = 0;
            m_Location = loc;
            m_vcStart  = new GregorianDateTime(begDate);
            m_vcCount  = iCount;
            earth      = loc.GetEarthData();

            // alokacia pola
            m_pData = new VAISNAVADAY[nTotalCount];

            // inicializacia poctovych premennych
            m_nCount    = nTotalCount;
            m_PureCount = iCount;

            date = new GregorianDateTime();
            date.Set(begDate);
            date.shour         = 0.0;
            date.TimezoneHours = loc.OffsetUtcHours;
            date.SubtractDays(BEFORE_DAYS);
            date.InitWeekDay();

            weekday = date.dayOfWeek;

            GCFestivalSpecialExecutor exec = new GCFestivalSpecialExecutor(this);

            long utcDayStart = -1;
            long utcDayEnd   = -1;

            // 1
            // initialization of days
            for (i = 0; i < nTotalCount; i++)
            {
                m_pData[i]                = new VAISNAVADAY();
                m_pData[i].date           = new GregorianDateTime(date);
                m_pData[i].date.dayOfWeek = weekday;
                date.NextDay();
                weekday = (weekday + 1) % 7;
                m_pData[i].moonrise.SetValue(-1);
                m_pData[i].moonset.SetValue(-1);

                if (utcDayStart < 0)
                {
                    utcDayStart = Convert.ToInt64(m_pData[i].date.GetJulianComplete() * 86400);
                }
                m_pData[i].UtcDayStart = utcDayStart;
                utcDayStart           += 86400;
            }

            for (i = 0; i < nTotalCount; i++)
            {
                m_pData[i].Previous = i > 0 ? m_pData[i - 1] : null;
                m_pData[i].Next     = i < nTotalCount - 1 ? m_pData[i + 1] : null;
            }

            TResultCoreEvents recentEvents = null;

            // 2
            // calculating DST data and core events
            foreach (VAISNAVADAY t in m_pData)
            {
                t.BiasMinutes = loc.TimeZone.GetBiasMinutesForDay(t.date);
                if (t.Previous != null)
                {
                    t.DstDayType = (t.BiasMinutes == 0
                        ? (t.Previous.BiasMinutes == 0 ? DstTypeChange.DstOff : DstTypeChange.DstEnd)
                        : (t.Previous.BiasMinutes == 0 ? DstTypeChange.DstStart : DstTypeChange.DstOn));
                }

                utcDayStart = t.UtcDayStart - (t.Previous != null ? t.Previous.BiasMinutes * 60 : 0);
                utcDayEnd   = t.UtcDayStart + 86400 - t.BiasMinutes * 60;

                if (recentEvents == null || recentEvents.p_events.Count == 0 || recentEvents.Year != t.date.year)
                {
                    recentEvents = GCCoreAstronomy.GetCoreEventsYear(loc, t.date.year);
                }
                recentEvents.GetCoreEvents(t.coreEvents, utcDayStart, utcDayEnd);


                utcDayStart = utcDayEnd;
            }

            // 3
            if (bCalcMoon)
            {
                foreach (VAISNAVADAY t in m_pData)
                {
                    GCMoonData.CalcMoonTimes(earth, t.date, Convert.ToDouble(t.BiasMinutes / 60.0), out t.moonrise, out t.moonset);

                    if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_MOON_RISE) != 0 && t.moonrise.hour >= 0)
                    {
                        tempStr = t.Format(GCStrings.Localized("Moonrise {moonRiseTime} ({dstSig})"));
                        t.AddEvent(DisplayPriorities.PRIO_MOON, GCDS.CAL_MOON_RISE, tempStr);
                    }

                    if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_MOON_SET) != 0 && t.moonset.hour >= 0)
                    {
                        tempStr = t.Format(GCStrings.Localized("Moonset {moonSetTime} ({dstSig})"));
                        t.AddEvent(DisplayPriorities.PRIO_MOON, GCDS.CAL_MOON_SET, tempStr);
                    }
                }
            }

            // 4
            // init of astro data
            foreach (VAISNAVADAY t in m_pData)
            {
                t.astrodata = new GCAstroData();
                t.astrodata.DayCalc(t.date, earth);

                t.coreEvents.InsertByTime(new TCoreEvent()
                {
                    Time  = t.UtcDayStart + (long)t.astrodata.sunArunodaya.TotalSeconds,
                    nType = CoreEventType.CCTYPE_S_ARUN
                });
                t.coreEvents.InsertByTime(new TCoreEvent()
                {
                    Time  = t.UtcDayStart + (long)t.astrodata.sunRise.TotalSeconds,
                    nType = CoreEventType.CCTYPE_S_RISE
                });
                t.coreEvents.InsertByTime(new TCoreEvent()
                {
                    Time  = t.UtcDayStart + (long)t.astrodata.sunNoon.TotalSeconds,
                    nType = CoreEventType.CCTYPE_S_NOON
                });
                t.coreEvents.InsertByTime(new TCoreEvent()
                {
                    Time  = t.UtcDayStart + (long)t.astrodata.sunSet.TotalSeconds,
                    nType = CoreEventType.CCTYPE_S_SET
                });
            }

            // 5
            // init of masa
            foreach (VAISNAVADAY t in m_pData)
            {
                if (t.Previous == null ||
                    t.astrodata.sunRise.Paksa != t.Previous.astrodata.sunRise.Paksa)
                {
                    t.astrodata.MasaCalc(t.date, earth);
                    lastMasa  = t.astrodata.Masa;
                    lastGYear = t.astrodata.GaurabdaYear;
                }
                t.astrodata.Masa         = lastMasa;
                t.astrodata.GaurabdaYear = lastGYear;

                if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_SUN_LONG) != 0)
                {
                    tempStr = string.Format("{0}: {1} (*)", GCStrings.Localized("Sun Longitude")
                                            , t.astrodata.sunRise.longitude);
                    t.AddEvent(DisplayPriorities.PRIO_ASTRO, GCDS.CAL_SUN_LONG, tempStr);
                }

                if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_MOON_LONG) != 0)
                {
                    tempStr = string.Format("{0}: {1} (*)", GCStrings.Localized("Moon Longitude")
                                            , t.astrodata.sunRise.longitudeMoon);
                    t.AddEvent(DisplayPriorities.PRIO_ASTRO, GCDS.CAL_MOON_LONG, tempStr);
                }

                if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_AYANAMSHA) != 0)
                {
                    tempStr = string.Format("{0} {1} ({2}) (*)", GCStrings.Localized("Ayanamsha")
                                            , t.astrodata.Ayanamsa
                                            , GCAyanamsha.GetAyanamsaName(GCAyanamsha.GetAyanamsaType()));
                    t.AddEvent(DisplayPriorities.PRIO_ASTRO, GCDS.CAL_AYANAMSHA, tempStr);
                }

                if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_JULIAN) != 0)
                {
                    tempStr = string.Format("{0} {1} (*)", GCStrings.Localized("Julian Time")
                                            , t.astrodata.JulianDay);
                    t.AddEvent(DisplayPriorities.PRIO_ASTRO, GCDS.CAL_JULIAN, tempStr);
                }
            }


            if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_MASA_CHANGE) != 0)
            {
                String str;

                foreach (VAISNAVADAY t in m_pData)
                {
                    if (t.Previous != null && t.Previous.astrodata.Masa != t.astrodata.Masa)
                    {
                        str = t.Format(GCStrings.Localized("First day of {masaName} Masa"));
                        t.AddEvent(DisplayPriorities.PRIO_MASA_CHANGE, GCDS.CAL_MASA_CHANGE, str);
                    }

                    if (t.Next != null && t.Next.astrodata.Masa != t.astrodata.Masa)
                    {
                        str = t.Format(GCStrings.Localized("Last day of {masaName} Masa"));
                        t.AddEvent(DisplayPriorities.PRIO_MASA_CHANGE, GCDS.CAL_MASA_CHANGE, str);
                    }
                }
            }

            if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_DST_CHANGE) != 0)
            {
                foreach (VAISNAVADAY t in m_pData)
                {
                    if (t.Previous != null && t.Previous.BiasMinutes == 0 && t.BiasMinutes != 0)
                    {
                        t.AddEvent(DisplayPriorities.PRIO_DST_CHANGE, GCDS.CAL_DST_CHANGE, GCStrings.Localized("First day of Daylight Saving Time"));
                    }
                    else if (t.Next != null && t.BiasMinutes != 0 && t.Next.BiasMinutes == 0)
                    {
                        t.AddEvent(DisplayPriorities.PRIO_DST_CHANGE, GCDS.CAL_DST_CHANGE, GCStrings.Localized("Last day of Daylight Saving Time"));
                    }
                }
            }

            // 6
            // init of mahadvadasis
            foreach (VAISNAVADAY t in m_pData)
            {
                t.MahadvadasiCalc(earth);
            }

            //
            // init for Ekadasis
            foreach (VAISNAVADAY t in m_pData)
            {
                if (t.Previous == null)
                {
                    continue;
                }
                t.EkadasiCalc(earth);
                if (t.Previous.nFastID == FastType.FAST_EKADASI)
                {
                    t.CalculateEParana(earth);
                }
            }

            if (EkadasiOnly)
            {
                return(1);
            }

            // init ksaya data
            // init of second day of vriddhi
            CalculateKsayaVriddhiTithis();

            //
            // calculate sankrantis
            CalculateSankrantis();

            // 7
            // init of festivals
            AddMatchedFestivals(exec);

            //
            // apply daylight saving time
            ApplyDaylightSavingHours();

            //
            // resolve festivals fasting
            for (i = BEFORE_DAYS; i < m_PureCount + BEFORE_DAYS; i++)
            {
                ResolveFestivalsFasting(i);

                if (GCDisplaySettings.Current.getValue(GCDS.CAL_SUN_RISE) != 0)
                {
                    tempStr = string.Format("{0}-{1}-{2}  {3} - {4} - {5} ({6})",
                                            GCStrings.Localized("Sunrise"),
                                            GCStrings.Localized("Noon"),
                                            GCStrings.Localized("Sunset"),
                                            m_pData[i].astrodata.sunRise.ToShortTimeString(),
                                            m_pData[i].astrodata.sunNoon.ToShortTimeString(),
                                            m_pData[i].astrodata.sunSet.ToShortTimeString(),
                                            GCStrings.GetDSTSignature(m_pData[i].BiasMinutes));
                    m_pData[i].AddEvent(DisplayPriorities.PRIO_SUN, GCDS.CAL_SUN_RISE, tempStr);
                }

                if (GCDisplaySettings.Current.getValue(GCDS.CAL_SUN_SANDHYA) != 0)
                {
                    tempStr = string.Format("{0}: {1} | {2} | {3}   ({4})",
                                            GCStrings.Localized("Sandhyas"),
                                            m_pData[i].astrodata.sunRise.ShortSandhyaString(),
                                            m_pData[i].astrodata.sunNoon.ShortSandhyaString(),
                                            m_pData[i].astrodata.sunSet.ShortSandhyaString(),
                                            GCStrings.GetDSTSignature(m_pData[i].BiasMinutes));
                    m_pData[i].AddEvent(DisplayPriorities.PRIO_SUN, GCDS.CAL_SUN_SANDHYA, tempStr);
                }

                if (GCDisplaySettings.Current.getValue(GCDS.CAL_BRAHMA_MUHURTA) != 0)
                {
                    tempStr = string.Format("{0}: {1}   ({2})",
                                            GCStrings.Localized("Brahma Muhurta"),
                                            m_pData[i].astrodata.sunRise.ShortMuhurtaString(-2),
                                            GCStrings.GetDSTSignature(m_pData[i].BiasMinutes));
                    m_pData[i].AddEvent(DisplayPriorities.PRIO_SUN, GCDS.CAL_BRAHMA_MUHURTA, tempStr);
                }
            }

            if (GCDisplaySettings.Current.getValue(GCDS.CAL_COREEVENTS) != 0)
            {
                int number = 1;
                foreach (VAISNAVADAY today in m_pData)
                {
                    foreach (TCoreEvent tde in today.coreEvents)
                    {
                        m_pData[i].AddEvent(DisplayPriorities.PRIO_ASTRO + number, GCDS.CAL_COREEVENTS,
                                            tde.TypeString + "   " + today.GetCoreEventTime(tde));
                        number++;
                    }
                }
            }


            // sorting day events according priority
            VAISNAVAEVENTComparer vec = new VAISNAVAEVENTComparer();

            foreach (VAISNAVADAY t in m_pData)
            {
                t.dayEvents.Sort(vec);
            }


            return(1);
        }
Пример #8
0
 /// <summary>
 /// returns true, if on exec.day(0) should be observed this event
 /// </summary>
 /// <param name="exec"></param>
 /// <returns></returns>
 public virtual bool IsFestivalDay(GCFestivalSpecialExecutor exec)
 {
     return(false);
 }
 public override bool IsFestivalDay(GCFestivalSpecialExecutor exec)
 {
     return(testFestival(exec, false));
 }
Пример #10
0
 public override bool IsFestivalDay(GCFestivalSpecialExecutor exec)
 {
     return(exec.day(-DayOffset).sankranti_zodiac == RasiOfSun);
 }