def GetFirstDayOfYear(earth, nYear):

    a = [2, 15, 3, 1, 3, 15, 4, 1, 4, 15]
    d = GCGregorianDate()
    day = GCDayData()

    if nYear >= 1950 and nYear < 2058:
        tmp = gGaurBeg[(nYear - 1950) * 26 + 22]
        d.month = (tmp & 0x3e0) >> 5
        d.day = (tmp & 0x1f)
        d.year = nYear
        d.NextDay()
        a[0] = d.month
        a[1] = d.day

    for i in range(0, 10, 2):
        d.year = nYear
        d.month = a[i]
        d.day = a[i + 1]

        day.DayCalc(d, earth)
        masa = day.MasaCalc(d, earth)
        gy = day.nGaurabdaYear

        if masa == 11:  # visnu masa
            while True:
                # shifts date
                step = max(int(day.nTithi / 2), 1)
                for j in range(step):
                    d.PreviousDay()
                # try new time
                day.DayCalc(d, earth)
                if day.nTithi >= 28: break
            d.NextDay()
            d.tzone = earth.tzone
            d.shour = day.sun.sunrise_deg / 360.0
            return d

    d.year = -1
    d.month = -1
    d.day = -1
    d.tzone = earth.tzone
    d.shour = day.sun.sunrise_deg / 360.0

    return d
Esempio n. 2
0
    def writeHtml(self, stream):
        stream.write("<html>\n<head>\n<title>Core Events</title>\n\n")
        stream.write(
            "<style>\n<!--\nbody {\n  font-family:Verdana;\n  font-size:11pt;\n}\n\ntd.hed {\n  font-size:11pt;\n  font-weight:bold;\n"
        )
        stream.write(
            "  background:#aaaaaa;\n  color:white;\n  text-align:center;\n  vertical-align:center;\n  padding-left:15pt;\n  padding-right:15pt;\n"
        )
        stream.write(
            "  padding-top:5pt;\n  padding-bottom:5pt;\n}\n-->\n</style>\n")
        stream.write("</head>\n")
        stream.write("<body>\n\n")
        stream.write(
            "<h1 align=center>Events</h1>\n<p align=center>From {} to {}.</p>\n\n"
            .format(self.m_vcStart, self.m_vcEnd))

        stream.write("<p align=center>{}</p>\n".format(
            self.m_location.m_strFullName))

        prevd = GCGregorianDate()
        prevd.day = 0
        prevd.month = 0
        prevd.year = 0
        prevt = -1

        stream.write("<table align=center><tr>\n")
        last_header = ''
        new_header = ''
        for dnr in self.p_events:
            if self.b_sorted:
                new_header = " {} - {} ".format(
                    dnr.Time, GCStrings.GetDayOfWeek(dnr.Time.dayOfWeek))
            else:
                new_header = self.header_text[dnr.nType]
            if last_header != new_header:
                stream.write(
                    f"<td class=\"hed\" colspan=2>{new_header}</td></tr>\n<tr>\n"
                )
                last_header = new_header

            stream.write("<td>{}</td><td>{}</td></tr><tr>\n".format(
                dnr.EventText(), dnr.Time.time_str()))

        stream.write("</tr></table>\n")
        stream.write(
            "<hr align=center width=\"50%%\">\n<p align=center>Generated by {}</p>"
            .format(GCStrings.getString(130)))
        stream.write("</body>\n</html>\n")
        return 1
Esempio n. 3
0
    def formatRtf(self, stream):
        sb = GCStringBuilder(stream)
        sb.Format = SBTF_RTF
        sb.fontSizeH1 = GCLayoutData.textSizeH1
        sb.fontSizeH2 = GCLayoutData.textSizeH2
        sb.fontSizeText = GCLayoutData.textSizeText
        sb.fontSizeNote = GCLayoutData.textSizeNote

        sb.AppendDocumentHeader()

        sb.AppendHeader1("Events")

        stream.write("\\par from {} to {}.\\par\r\n\\par\r\n".format(
            self.m_vcStart, self.m_vcEnd))
        stream.write("{}\\par\r\n\\par\r\n".format(
            self.m_location.m_strFullName))

        prevd = GCGregorianDate()
        prevd.day = 0
        prevd.month = 0
        prevd.year = 0
        prevt = -1

        last_header = ''
        for dnr in self.p_events:
            new_header = ''
            if self.b_sorted:
                new_header = " {} - {} ".format(
                    dnr.Time, GCStrings.GetDayOfWeek(dnr.Time.dayOfWeek))
            else:
                new_header = header_text[dnr.nType]
            if last_header != new_header:
                sb.AppendLine()
                sb.AppendHeader2(new_header)
                sb.AppendLine()
                last_header = new_header

            stream.write("\\par            {} {}    {}".format(
                dnr.Time.time_str(), GCStrings.GetDSTSignature(dnr.nDst),
                dnr.EventText()))

        sb.AppendLine()
        sb.AppendNote()
        sb.AppendDocumentTail()
        return 1
Esempio n. 4
0
    def formatText(self, stream):
        sb = GCStringBuilder(stream)
        sb.Format = SBTF_TEXT

        stream.write("Events from {} to {}.\r\n\r\n".format(
            self.m_vcStart, self.m_vcEnd))
        stream.write("{}\r\n\r\n".format(self.m_location.m_strFullName))

        prevd = GCGregorianDate()
        prevd.day = 0
        prevd.month = 0
        prevd.year = 0
        prevt = -1

        last_header = ''
        for dnr in self.p_events:
            new_header = ''
            if self.b_sorted:
                new_header = " {} - {} ".format(
                    dnr.Time, GCStrings.GetDayOfWeek(dnr.Time.dayOfWeek))
            else:
                new_header = header_text[dnr.nType]
            if last_header != new_header:
                sb.AppendLine()
                sb.AppendHeader3(new_header)
                sb.AppendLine()
                last_header = new_header

            stream.write("            {} {}    {}".format(
                dnr.Time.time_str(), GCStrings.GetDSTSignature(dnr.nDst),
                dnr.EventText()))
            sb.AppendLine()

        sb.AppendLine()
        sb.AppendNote()
        return 1
Esempio n. 5
0
def CalcTithiDate(nGYear, nMasa, nPaksa, nTithi, earth):
    i = 0
    gy = 0
    d = GCGregorianDate()
    dtemp = GCGregorianDate()
    day = GCDayData()
    tithi = 0
    counter = 0
    tmp = 0

    if nGYear >= 464 and nGYear < 572:
        tmp = gGaurBeg[(nGYear - 464) * 26 + nMasa * 2 + nPaksa]
        d.month = (tmp & 0x3e0) >> 5
        d.day = (tmp & 0x1f)
        d.year = (tmp & 0xfffc00) >> 10
        d.tzone = earth.tzone
        d.NextDay()

        day.DayCalc(d, earth)
        day.nMasa = day.MasaCalc(d, earth)
        gy = day.nGaurabdaYear
    else:
        #d = GetFirstDayOfYear(earth, nGYear + 1486)
        d.day = 15
        d.month = 2 + nMasa
        d.year = nGYear + 1486
        if d.month > 12:
            d.month -= 12
            d.year += 1
        d.shour = 0.5
        d.tzone = earth.tzone

        i = 0
        while True:
            d.AddDays(13)
            day.DayCalc(d, earth)
            day.nMasa = day.MasaCalc(d, earth)
            gy = day.nGaurabdaYear
            i += 1
            if i >= 30: break
            if (day.nPaksa == nPaksa) and (day.nMasa == nMasa): break

    if i >= 30:
        d.year = d.month = d.day = -1
        return d

    # we found masa and paksa
    # now we have to find tithi
    tithi = nTithi + nPaksa * 15

    if day.nTithi == tithi:
        # loc1
        # find tithi juncts in this day and according to that times,
        # look in previous or next day for end and start of this tithi
        d.PreviousDay()
        day.DayCalc(d, earth)
        if (day.nTithi > tithi) and (day.nPaksa != nPaksa):
            d.NextDay()
        return d

    if day.nTithi < tithi:
        # do increment of date until nTithi == tithi
        #   but if nTithi > tithi
        #       then do decrement of date
        counter = 0
        while counter < 16:
            d.NextDay()
            day.DayCalc(d, earth)
            if day.nTithi == tithi:
                return d
            if (day.nTithi < tithi) and (day.nPaksa != nPaksa):
                return d
            if day.nTithi > tithi:
                return d
            counter += 1
        # somewhere is error
        d.year = d.month = d.day = 0
        return d
    else:
        # do decrement of date until nTithi <= tithi
        counter = 0
        while counter < 16:
            d.PreviousDay()
            day.DayCalc(d, earth)
            if day.nTithi == tithi:
                return d
            if (day.nTithi > tithi) and (day.nPaksa != nPaksa):
                d.NextDay()
                return d
            if day.nTithi < tithi:
                d.NextDay()
                return d
            counter += 1
        # somewhere is error
        d.year = d.month = d.day = 0
        return d

    # now we know the type of day-accurancy
    # nType = 0 means, that we dont found a day
    # nType = 1 means, we find day, when tithi was present at sunrise
    # nType = 2 means, we found day, when tithi started after sunrise
    #                  but ended before next sunrise
    #

    return d
Esempio n. 6
0
def CalcTithiEndEx(vcStart, GYear, nMasa, nPaksa, nTithi, earth, endTithi):
    d = GCGregorianDate()
    dtemp = GCGregorianDate()
    day = GCDayData()
    tithi = 0
    counter = 0
    sunrise = 0.0
    start = GCGregorianDate()
    end = GCGregorianDate()
    start.shour = -1.0
    end.shour = -1.0
    start.day = start.month = start.year = -1
    end.day = end.month = end.year = -1

    d.Set(vcStart)

    i = 0
    while True:
        d.AddDays(13)
        day.DayCalc(d, earth)
        day.nMasa = day.MasaCalc(d, earth)
        gy = day.nGaurabdaYear
        i += 1
        if ((day.nPaksa == nPaksa) and (day.nMasa == nMasa)) or i > 30:
            break

    if i > 30:
        d.year = d.month = d.day = -1
        return d

    # we found masa and paksa
    # now we have to find tithi
    tithi = nTithi + nPaksa * 15

    if day.nTithi == tithi:
        # loc1
        # find tithi juncts in this day and according to that times,
        # look in previous or next day for end and start of this tithi
        nType = 1
    else:
        if day.nTithi < tithi:
            # do increment of date until nTithi == tithi
            #   but if nTithi > tithi
            #       then do decrement of date
            counter = 0
            while counter < 30:
                d.NextDay()
                day.DayCalc(d, earth)
                if day.nTithi == tithi:
                    break
                if (day.nTithi < tithi) and (day.nPaksa != nPaksa):
                    d.PreviousDay()
                    break
                if day.nTithi > tithi:
                    d.PreviousDay()
                    break
                counter += 1
            # somewhere is error
            if counter >= 30:
                d.year = d.month = d.day = 0
                nType = 0
        else:
            # do decrement of date until nTithi <= tithi
            counter = 0
            while counter < 30:
                d.PreviousDay()
                day.DayCalc(d, earth)
                if day.nTithi == tithi:
                    break
                if (day.nTithi > tithi) and (day.nPaksa != nPaksa):
                    break
                if day.nTithi < tithi:
                    break
                counter += 1
            # somewhere is error
            if counter >= 30:
                d.year = d.month = d.day = 0
                nType = 0

        if day.nTithi == tithi:
            # do the same as in loc1
            nType = 1
        else:
            # nTithi != tithi and nTithi < tithi
            # but on next day is nTithi > tithi
            # that means we will find start and the end of tithi
            # in this very day or on next day before sunrise
            nType = 2

    # now we know the type of day-accurancy
    # nType = 0 means, that we dont found a day
    # nType = 1 means, we find day, when tithi was present at sunrise
    # nType = 2 means, we found day, when tithi started after sunrise
    #                  but ended before next sunrise
    #
    sunrise = day.sun.sunrise_deg / 360 + earth.tzone / 24

    if nType == 1:
        d1 = GCGregorianDate()
        d2 = GCGregorianDate()
        d.shour = sunrise
        GCTithi.GetPrevTithiStart(earth, d, d1)
        #d = d1
        #d.shour += 0.02
        GCTithi.GetNextTithiStart(earth, d, d2)

        endTithi.Set(d2)
        return d1
    elif nType == 2:
        d1 = GCGregorianDate()
        d2 = GCGregorianDate()
        d.shour = sunrise
        GCTithi.GetNextTithiStart(earth, d, d1)
        d.Set(d1)
        d.shour += 0.1
        d.NormalizeValues()
        GCTithi.GetNextTithiStart(earth, d, d2)

        endTithi.Set(d2)
        return d1

    # if nType == 0, then this algoritmus has some failure
    if nType == 0:
        d.year = 0
        d.month = 0
        d.day = 0
        d.shour = 0.0
        endTithi.Set(d)
    else:
        d.Set(start)
        endTithi.Set(end)

    return d