Example #1
0
def jd_to(jd):
    ## The calendar is closely synchronized to the Gregorian Calendar, always starting on the same day
    ## We can use this and the regular sequence of days in months to do a simple conversion by finding
    ## what day in the Gregorian year the Julian Day number is, converting this to the day in the
    ## Indian year and subtracting off the required number of months and days to get the final date

    gregorianYear, gregorianMonth, gregorianDay = gregorian.jd_to(jd)
    jdGregorianFirstDayOfYear = gregorian.to_jd(gregorianYear, 1, 1)
    gregorianDayOfYear = jd - jdGregorianFirstDayOfYear + 1

    ## There is a fixed 78 year difference between year numbers, but the years do not exactly match up,
    ## there is a fixed 80 day difference between the first day of the year, if the Gregorian day of
    ## the year is 80 or less then the equivalent Indian day actually falls in the preceding    year
    if gregorianDayOfYear > 80:
        year = gregorianYear - 78
    else:
        year = gregorianYear - 79

    ## If it is a leap year then the first month has 31 days, otherwise 30.
    if isLeap(year):
        daysInMonth1 = 31
    else:
        daysInMonth1 = 30

    ## The Indian year always starts 80 days after the Gregorian year, calculate the Indian day of
    ## the year, taking into account if it falls into the previous Gregorian year
    if gregorianDayOfYear>80:
        indianDayOfYear = gregorianDayOfYear - 80
    else:
        indianDayOfYear = gregorianDayOfYear + daysInMonth1 + 5*31    + 6*30 - 80

    ## Then simply remove the whole months from the day of the year and you are left with the day of month
    if indianDayOfYear <= daysInMonth1:
        month = 1
        day = indianDayOfYear
    elif indianDayOfYear <= daysInMonth1 + 5*31:
        month = (indianDayOfYear-daysInMonth1-1) // 31 + 2
        day = indianDayOfYear - daysInMonth1 - (month-2)*31
    else:
        month = (indianDayOfYear - daysInMonth1 - 5*31 - 1) // 30 + 7
        day = indianDayOfYear - daysInMonth1 - 5*31 - (month-7)*30
    return (year, month, day)
Example #2
0
def jd_to(jd):
    ## The calendar is closely synchronized to the Gregorian Calendar, always starting on the same day
    ## We can use this and the regular sequence of days in months to do a simple conversion by finding
    ## what day in the Gregorian year the Julian Day number is, converting this to the day in the
    ## Indian year and subtracting off the required number of months and days to get the final date

    gregorianYear, gregorianMonth, gregorianDay = gregorian.jd_to(jd)
    jdGregorianFirstDayOfYear = gregorian.to_jd(gregorianYear, 1, 1)
    gregorianDayOfYear = jd - jdGregorianFirstDayOfYear + 1

    ## There is a fixed 78 year difference between year numbers, but the years do not exactly match up,
    ## there is a fixed 80 day difference between the first day of the year, if the Gregorian day of
    ## the year is 80 or less then the equivalent Indian day actually falls in the preceding    year
    if gregorianDayOfYear > 80:
        year = gregorianYear - 78
    else:
        year = gregorianYear - 79

    ## If it is a leap year then the first month has 31 days, otherwise 30.
    if isLeap(year):
        daysInMonth1 = 31
    else:
        daysInMonth1 = 30

    ## The Indian year always starts 80 days after the Gregorian year, calculate the Indian day of
    ## the year, taking into account if it falls into the previous Gregorian year
    if gregorianDayOfYear > 80:
        indianDayOfYear = gregorianDayOfYear - 80
    else:
        indianDayOfYear = gregorianDayOfYear + daysInMonth1 + 5 * 31 + 6 * 30 - 80

    ## Then simply remove the whole months from the day of the year and you are left with the day of month
    if indianDayOfYear <= daysInMonth1:
        month = 1
        day = indianDayOfYear
    elif indianDayOfYear <= daysInMonth1 + 5 * 31:
        month = (indianDayOfYear - daysInMonth1 - 1) // 31 + 2
        day = indianDayOfYear - daysInMonth1 - (month - 2) * 31
    else:
        month = (indianDayOfYear - daysInMonth1 - 5 * 31 - 1) // 30 + 7
        day = indianDayOfYear - daysInMonth1 - 5 * 31 - (month - 7) * 30
    return (year, month, day)
Example #3
0
def isow(jd):## iso week number
    year = gregorian.jd_to(jd - 3)[0]
    if jd>=iso_to_jd(year+1, 1, 1):
        year += 1
    return (jd - iso_to_jd(year, 1, 1)) // 7 + 1
Example #4
0
def isow_year(jd):## iso week year
    year = gregorian.jd_to(jd - 3)[0]
    if jd>=iso_to_jd(year+1, 1, 1):
        year += 1
    return year
Example #5
0
def isow(jd):  ## iso week number
    year = gregorian.jd_to(jd - 3)[0]
    if jd >= iso_to_jd(year + 1, 1, 1):
        year += 1
    return (jd - iso_to_jd(year, 1, 1)) // 7 + 1
Example #6
0
def isow_year(jd):  ## iso week year
    year = gregorian.jd_to(jd - 3)[0]
    if jd >= iso_to_jd(year + 1, 1, 1):
        year += 1
    return year