Calendar updates
svn: r1247
This commit is contained in:
parent
2a5754adef
commit
1e1ef8dc73
3
configure
vendored
3
configure
vendored
@ -3878,7 +3878,7 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ac_config_files="$ac_config_files Makefile src/Makefile src/const.py src/docgen/Makefile src/filters/Makefile src/plugins/Makefile src/data/Makefile src/data/templates/Makefile src/po/Makefile doc/Makefile doc/gramps-manual/Makefile doc/gramps-manual/C/Makefile doc/extending-gramps/Makefile doc/extending-gramps/C/Makefile omf-install/Makefile gramps.spec gramps.sh"
|
ac_config_files="$ac_config_files Makefile src/Makefile src/const.py src/docgen/Makefile src/filters/Makefile src/plugins/Makefile src/calendars/Makefile src/data/Makefile src/data/templates/Makefile src/po/Makefile doc/Makefile doc/gramps-manual/Makefile doc/gramps-manual/C/Makefile doc/extending-gramps/Makefile doc/extending-gramps/C/Makefile omf-install/Makefile gramps.spec gramps.sh"
|
||||||
cat >confcache <<\_ACEOF
|
cat >confcache <<\_ACEOF
|
||||||
# This file is a shell script that caches the results of configure
|
# This file is a shell script that caches the results of configure
|
||||||
# tests run on this system so they can be shared between configure
|
# tests run on this system so they can be shared between configure
|
||||||
@ -4399,6 +4399,7 @@ do
|
|||||||
"src/docgen/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/docgen/Makefile" ;;
|
"src/docgen/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/docgen/Makefile" ;;
|
||||||
"src/filters/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/filters/Makefile" ;;
|
"src/filters/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/filters/Makefile" ;;
|
||||||
"src/plugins/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/plugins/Makefile" ;;
|
"src/plugins/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/plugins/Makefile" ;;
|
||||||
|
"src/calendars/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/calendars/Makefile" ;;
|
||||||
"src/data/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/data/Makefile" ;;
|
"src/data/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/data/Makefile" ;;
|
||||||
"src/data/templates/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/data/templates/Makefile" ;;
|
"src/data/templates/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/data/templates/Makefile" ;;
|
||||||
"src/po/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/po/Makefile" ;;
|
"src/po/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/po/Makefile" ;;
|
||||||
|
@ -276,6 +276,7 @@ src/const.py
|
|||||||
src/docgen/Makefile
|
src/docgen/Makefile
|
||||||
src/filters/Makefile
|
src/filters/Makefile
|
||||||
src/plugins/Makefile
|
src/plugins/Makefile
|
||||||
|
src/calendars/Makefile
|
||||||
src/data/Makefile
|
src/data/Makefile
|
||||||
src/data/templates/Makefile
|
src/data/templates/Makefile
|
||||||
src/po/Makefile
|
src/po/Makefile
|
||||||
|
735
src/Calendar.py
735
src/Calendar.py
@ -154,8 +154,8 @@ class Calendar:
|
|||||||
except:
|
except:
|
||||||
return "Illegal Month"
|
return "Illegal Month"
|
||||||
|
|
||||||
def check(self):
|
def check(self,year,month,day):
|
||||||
return 0
|
return 1
|
||||||
|
|
||||||
def quote_display(self,year,month,day,mode):
|
def quote_display(self,year,month,day,mode):
|
||||||
return "%s (%s)" % (text,Calendar.NAME)
|
return "%s (%s)" % (text,Calendar.NAME)
|
||||||
@ -511,731 +511,6 @@ class Calendar:
|
|||||||
|
|
||||||
return (year,month,day,mode)
|
return (year,month,day,mode)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Hebrew calendar
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
class Hebrew(Calendar):
|
|
||||||
"""Jewish Calendar"""
|
|
||||||
|
|
||||||
HALAKIM_PER_HOUR = 1080
|
|
||||||
HALAKIM_PER_DAY = 25920
|
|
||||||
HALAKIM_PER_LUNAR_CYCLE = ((29 * HALAKIM_PER_DAY) + 13753)
|
|
||||||
HALAKIM_PER_METONIC_CYCLE = (HALAKIM_PER_LUNAR_CYCLE * (12 * 19 + 7))
|
|
||||||
|
|
||||||
SDN_OFFSET = 347997
|
|
||||||
NEW_MOON_OF_CREATION = 31524
|
|
||||||
|
|
||||||
SUNDAY = 0
|
|
||||||
MONDAY = 1
|
|
||||||
TUESDAY = 2
|
|
||||||
WEDNESDAY= 3
|
|
||||||
FRIDAY = 5
|
|
||||||
|
|
||||||
NOON = (18 * HALAKIM_PER_HOUR)
|
|
||||||
AM3_11_20 = ((9 * HALAKIM_PER_HOUR) + 204)
|
|
||||||
AM9_32_43 = ((15 * HALAKIM_PER_HOUR) + 589)
|
|
||||||
|
|
||||||
monthsPerYear = [
|
|
||||||
12, 12, 13, 12, 12, 13, 12, 13, 12, 12,
|
|
||||||
13, 12, 12, 13, 12, 12, 13, 12, 13 ]
|
|
||||||
|
|
||||||
yearOffset = [
|
|
||||||
0, 12, 24, 37, 49, 61, 74, 86, 99, 111, 123,
|
|
||||||
136, 148, 160, 173, 185, 197, 210, 222 ]
|
|
||||||
|
|
||||||
MONTHS = [
|
|
||||||
"Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "AdarI",
|
|
||||||
"AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz", "Av",
|
|
||||||
"Elul",]
|
|
||||||
|
|
||||||
M2NUM = {
|
|
||||||
"tishri" : 1, "heshvan" : 2, "kislev" : 3, "tevet" : 4,
|
|
||||||
"shevat" : 5, "adari" : 6, "adarii" : 7, "nisan" : 8,
|
|
||||||
"iyyar" : 9, "sivan" :10, "tammuz" :11, "av" : 12,
|
|
||||||
"elul" : 13,"tsh" : 1, "csh" : 2, "ksl" : 3,
|
|
||||||
"tvt" : 4, "shv" : 5, "adr" : 6, "ads" : 7,
|
|
||||||
"nsn" : 8, "iyr" : 9, "svn" :10, "tmz" : 11,
|
|
||||||
"aav" :12, "ell" :13,
|
|
||||||
}
|
|
||||||
|
|
||||||
NAME = "Hebrew"
|
|
||||||
TNAME = _("Hebrew")
|
|
||||||
|
|
||||||
def quote_display(self,year,month,day,mode):
|
|
||||||
return "%s (%s)" % (self.display(year,month,day,mode),Hebrew.NAME)
|
|
||||||
|
|
||||||
def month(self,val):
|
|
||||||
try:
|
|
||||||
return Hebrew.MONTHS[val-1]
|
|
||||||
except:
|
|
||||||
return "Illegal Month"
|
|
||||||
|
|
||||||
def set_month_string(self,text):
|
|
||||||
try:
|
|
||||||
return Hebrew.M2NUM[unicode(text.lower())]
|
|
||||||
except KeyError:
|
|
||||||
return UNDEF
|
|
||||||
|
|
||||||
def Tishri1(self,metonicYear, moladDay, moladHalakim):
|
|
||||||
|
|
||||||
tishri1 = moladDay
|
|
||||||
dow = tishri1 % 7
|
|
||||||
leapYear = metonicYear in [ 2, 5, 7, 10, 13, 16, 18]
|
|
||||||
lastWasLeapYear = metonicYear in [ 3, 6, 8, 11, 14, 17, 0]
|
|
||||||
|
|
||||||
# Apply rules 2, 3 and 4.
|
|
||||||
if ((moladHalakim >= Hebrew.NOON) or
|
|
||||||
((not leapYear) and dow == Hebrew.TUESDAY and
|
|
||||||
moladHalakim >= Hebrew.AM3_11_20) or
|
|
||||||
(lastWasLeapYear and dow == Hebrew.MONDAY and moladHalakim >= Hebrew.AM9_32_43)) :
|
|
||||||
tishri1 = tishri1 + 1
|
|
||||||
dow = dow + 1
|
|
||||||
if dow == 7:
|
|
||||||
dow = 0
|
|
||||||
|
|
||||||
# Apply rule 1 after the others because it can cause an additional
|
|
||||||
# delay of one day
|
|
||||||
|
|
||||||
if dow == Hebrew.WEDNESDAY or dow == Hebrew.FRIDAY or dow == Hebrew.SUNDAY:
|
|
||||||
tishri1 = tishri1 + 1
|
|
||||||
|
|
||||||
return tishri1
|
|
||||||
|
|
||||||
def MoladOfMetonicCycle(self,metonicCycle):
|
|
||||||
|
|
||||||
# Start with the time of the first molad after creation.
|
|
||||||
|
|
||||||
r1 = Hebrew.NEW_MOON_OF_CREATION
|
|
||||||
|
|
||||||
# Calculate metonicCycle * HALAKIM_PER_METONIC_CYCLE. The upper 32
|
|
||||||
# bits of the result will be in r2 and the lower 16 bits will be
|
|
||||||
# in r1.
|
|
||||||
|
|
||||||
r1 = r1 + (metonicCycle * (Hebrew.HALAKIM_PER_METONIC_CYCLE & 0xFFFF))
|
|
||||||
r2 = r1 >> 16
|
|
||||||
r2 = r2 + (metonicCycle * ((Hebrew.HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF))
|
|
||||||
|
|
||||||
# Calculate r2r1 / HALAKIM_PER_DAY. The remainder will be in r1, the
|
|
||||||
# upper 16 bits of the quotient will be in d2 and the lower 16 bits
|
|
||||||
# will be in d1.
|
|
||||||
|
|
||||||
d2 = r2 / Hebrew.HALAKIM_PER_DAY
|
|
||||||
r2 = r2 - (d2 * Hebrew.HALAKIM_PER_DAY)
|
|
||||||
r1 = (r2 << 16) | (r1 & 0xFFFF)
|
|
||||||
d1 = r1 / Hebrew.HALAKIM_PER_DAY
|
|
||||||
r1 = r1 - ( d1 * Hebrew.HALAKIM_PER_DAY)
|
|
||||||
|
|
||||||
MoladDay = (d2 << 16) | d1
|
|
||||||
MoladHalakim = r1
|
|
||||||
|
|
||||||
return (MoladDay,MoladHalakim)
|
|
||||||
|
|
||||||
def TishriMolad(self,inputDay):
|
|
||||||
|
|
||||||
# Estimate the metonic cycle number. Note that this may be an under
|
|
||||||
# estimate because there are 6939.6896 days in a metonic cycle not
|
|
||||||
# 6940, but it will never be an over estimate. The loop below will
|
|
||||||
# correct for any error in this estimate. */
|
|
||||||
|
|
||||||
metonicCycle = (inputDay + 310) / 6940
|
|
||||||
|
|
||||||
# Calculate the time of the starting molad for this metonic cycle. */
|
|
||||||
|
|
||||||
(moladDay, moladHalakim) = self.MoladOfMetonicCycle(metonicCycle)
|
|
||||||
|
|
||||||
# If the above was an under estimate, increment the cycle number until
|
|
||||||
# the correct one is found. For modern dates this loop is about 98.6%
|
|
||||||
# likely to not execute, even once, because the above estimate is
|
|
||||||
# really quite close.
|
|
||||||
|
|
||||||
while moladDay < (inputDay - 6940 + 310):
|
|
||||||
metonicCycle = metonicCycle + 1
|
|
||||||
moladHalakim = moladHalakim + Hebrew.HALAKIM_PER_METONIC_CYCLE
|
|
||||||
moladDay = moladDay + ( moladHalakim / Hebrew.HALAKIM_PER_DAY)
|
|
||||||
moladHalakim = moladHalakim % Hebrew.HALAKIM_PER_DAY
|
|
||||||
|
|
||||||
# Find the molad of Tishri closest to this date.
|
|
||||||
|
|
||||||
for metonicYear in range(0,18):
|
|
||||||
if moladDay > inputDay - 74:
|
|
||||||
break
|
|
||||||
|
|
||||||
moladHalakim = moladHalakim + \
|
|
||||||
(Hebrew.HALAKIM_PER_LUNAR_CYCLE * Hebrew.monthsPerYear[metonicYear])
|
|
||||||
moladDay = moladDay + (moladHalakim / Hebrew.HALAKIM_PER_DAY)
|
|
||||||
moladHalakim = moladHalakim % Hebrew.HALAKIM_PER_DAY
|
|
||||||
else:
|
|
||||||
metonicYear = metonicYear + 1
|
|
||||||
return (metonicCycle, metonicYear, moladDay, moladHalakim)
|
|
||||||
|
|
||||||
def StartOfYear(self,year):
|
|
||||||
|
|
||||||
MetonicCycle = (year - 1) / 19;
|
|
||||||
MetonicYear = (year - 1) % 19;
|
|
||||||
(MoladDay, MoladHalakim) = self.MoladOfMetonicCycle(MetonicCycle)
|
|
||||||
|
|
||||||
MoladHalakim = MoladHalakim + (Hebrew.HALAKIM_PER_LUNAR_CYCLE * Hebrew.yearOffset[MetonicYear])
|
|
||||||
MoladDay = MoladDay + (MoladHalakim / Hebrew.HALAKIM_PER_DAY)
|
|
||||||
MoladHalakim = MoladHalakim % Hebrew.HALAKIM_PER_DAY
|
|
||||||
|
|
||||||
pTishri1 = self.Tishri1(MetonicYear, MoladDay, MoladHalakim);
|
|
||||||
|
|
||||||
return (MetonicCycle, MetonicYear, MoladDay, MoladHalakim, pTishri1)
|
|
||||||
|
|
||||||
def get_ymd(self,sdn):
|
|
||||||
"""Converts an SDN number to a Julian calendar date"""
|
|
||||||
|
|
||||||
if sdn <= Hebrew.SDN_OFFSET :
|
|
||||||
return (0,0,0)
|
|
||||||
|
|
||||||
inputDay = sdn - Hebrew.SDN_OFFSET
|
|
||||||
|
|
||||||
(metonicCycle, metonicYear, day, halakim) = self.TishriMolad(inputDay)
|
|
||||||
tishri1 = self.Tishri1(metonicYear, day, halakim);
|
|
||||||
|
|
||||||
if inputDay >= tishri1:
|
|
||||||
# It found Tishri 1 at the start of the year
|
|
||||||
|
|
||||||
Year = (metonicCycle * 19) + metonicYear + 1
|
|
||||||
if inputDay < tishri1 + 59:
|
|
||||||
if inputDay < tishri1 + 30:
|
|
||||||
Month = 1
|
|
||||||
Day = inputDay - tishri1 + 1
|
|
||||||
else:
|
|
||||||
Month = 2
|
|
||||||
Day = inputDay - tishri1 - 29
|
|
||||||
return (Year, Month, Day)
|
|
||||||
|
|
||||||
# We need the length of the year to figure this out, so find
|
|
||||||
# Tishri 1 of the next year. */
|
|
||||||
|
|
||||||
halakim = halakim + (Hebrew.HALAKIM_PER_LUNAR_CYCLE * Hebrew.monthsPerYear[metonicYear])
|
|
||||||
day = day + (halakim / Hebrew.HALAKIM_PER_DAY)
|
|
||||||
halakim = halakim % Hebrew.HALAKIM_PER_DAY;
|
|
||||||
tishri1After = self.Tishri1((metonicYear + 1) % 19, day, halakim);
|
|
||||||
else:
|
|
||||||
# It found Tishri 1 at the end of the year.
|
|
||||||
|
|
||||||
Year = metonicCycle * 19 + metonicYear
|
|
||||||
if inputDay >= tishri1 - 177:
|
|
||||||
# It is one of the last 6 months of the year.
|
|
||||||
if inputDay > tishri1 - 30:
|
|
||||||
Month = 13
|
|
||||||
Day = inputDay - tishri1 + 30
|
|
||||||
elif inputDay > tishri1 - 60:
|
|
||||||
Month = 12
|
|
||||||
Day = inputDay - tishri1 + 60
|
|
||||||
elif inputDay > tishri1 - 89:
|
|
||||||
Month = 11
|
|
||||||
Day = inputDay - tishri1 + 89
|
|
||||||
elif inputDay > tishri1 - 119:
|
|
||||||
Month = 10
|
|
||||||
Day = inputDay - tishri1 + 119
|
|
||||||
elif inputDay > tishri1 - 148:
|
|
||||||
Month = 9
|
|
||||||
Day = inputDay - tishri1 + 148
|
|
||||||
else:
|
|
||||||
Month = 8
|
|
||||||
Day = inputDay - tishri1 + 178
|
|
||||||
return (Year,Month,Day)
|
|
||||||
else:
|
|
||||||
if Hebrew.monthsPerYear[(Year - 1) % 19] == 13:
|
|
||||||
Month = 7
|
|
||||||
Day = inputDay - tishri1 + 207
|
|
||||||
if Day > 0:
|
|
||||||
return (Year,Month,Day)
|
|
||||||
Month = Month - 1
|
|
||||||
Day = Day + 30
|
|
||||||
if Day > 0:
|
|
||||||
return (Year,Month,Day)
|
|
||||||
Month = Month - 1
|
|
||||||
Day = Day + 30
|
|
||||||
else:
|
|
||||||
Month = 6
|
|
||||||
Day = inputDay - tishri1 + 207
|
|
||||||
if Day > 0:
|
|
||||||
return (Year,Month,Day)
|
|
||||||
Month = Month - 1
|
|
||||||
Day = Day + 30
|
|
||||||
|
|
||||||
if Day > 0:
|
|
||||||
return (Year,Month,Day)
|
|
||||||
Month = Month - 1
|
|
||||||
Day = Day + 29
|
|
||||||
if Day > 0:
|
|
||||||
return (Year,Month,Day)
|
|
||||||
|
|
||||||
# We need the length of the year to figure this out, so find
|
|
||||||
# Tishri 1 of this year
|
|
||||||
tishri1After = tishri1;
|
|
||||||
(metonicCycle,metonicYear,day,halakim) = self.TishriMolad(day-365)
|
|
||||||
tishri1 = self.Tishri1(metonicYear, day, halakim)
|
|
||||||
|
|
||||||
yearLength = tishri1After - tishri1;
|
|
||||||
cday = inputDay - tishri1 - 29;
|
|
||||||
if yearLength == 355 or yearLength == 385 :
|
|
||||||
# Heshvan has 30 days
|
|
||||||
if day <= 30:
|
|
||||||
Month = 2
|
|
||||||
Day = cday
|
|
||||||
return (Year,Month,Day)
|
|
||||||
day = day - 30
|
|
||||||
else:
|
|
||||||
# Heshvan has 29 days
|
|
||||||
if day <= 29:
|
|
||||||
Month = 2
|
|
||||||
Day = cday
|
|
||||||
return (Year,Month,Day)
|
|
||||||
|
|
||||||
cday = cday - 29
|
|
||||||
|
|
||||||
# It has to be Kislev
|
|
||||||
return (Year,3,cday)
|
|
||||||
|
|
||||||
def get_sdn(self,year, month, day):
|
|
||||||
"""Converts a Jewish calendar date to an SDN number"""
|
|
||||||
if year <= 0 or day <= 0 or day > 30 :
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if month == 1 or month == 2:
|
|
||||||
# It is Tishri or Heshvan - don't need the year length.
|
|
||||||
(metonicCycle,metonicYear,moladDay,moladHalakim,tishri1) = self.StartOfYear(year)
|
|
||||||
if month == 1:
|
|
||||||
sdn = tishri1 + day - 1
|
|
||||||
else:
|
|
||||||
sdn = tishri1 + day + 29
|
|
||||||
elif month == 3:
|
|
||||||
# It is Kislev - must find the year length.
|
|
||||||
|
|
||||||
# Find the start of the year.
|
|
||||||
(metonicCycle,metonicYear,moladDay,moladHalakim,tishri1) = self.StartOfYear(year)
|
|
||||||
|
|
||||||
# Find the end of the year.
|
|
||||||
moladHalakim = moladHalakim + (Hebrew.HALAKIM_PER_LUNAR_CYCLE*Hebrew.monthsPerYear[metonicYear])
|
|
||||||
moladDay = moladDay + (moladHalakim / Hebrew.HALAKIM_PER_DAY)
|
|
||||||
moladHalakim = moladHalakim % Hebrew.HALAKIM_PER_DAY
|
|
||||||
tishri1After = self.Tishri1((metonicYear + 1) % 19, moladDay, moladHalakim)
|
|
||||||
|
|
||||||
yearLength = tishri1After - tishri1
|
|
||||||
|
|
||||||
if yearLength == 355 or yearLength == 385:
|
|
||||||
sdn = tishri1 + day + 59
|
|
||||||
else:
|
|
||||||
sdn = tishri1 + day + 58
|
|
||||||
elif month == 4 or month == 5 or month == 6:
|
|
||||||
# It is Tevet, Shevat or Adar I - don't need the year length
|
|
||||||
|
|
||||||
(metonicCycle,metonicYear,moladDay,moladHalakim,tishri1After) = self.StartOfYear(year+1)
|
|
||||||
|
|
||||||
if Hebrew.monthsPerYear[(year - 1) % 19] == 12:
|
|
||||||
lengthOfAdarIAndII = 29
|
|
||||||
else:
|
|
||||||
lengthOfAdarIAndII = 59
|
|
||||||
|
|
||||||
if month == 4:
|
|
||||||
sdn = tishri1After + day - lengthOfAdarIAndII - 237
|
|
||||||
elif month == 5:
|
|
||||||
sdn = tishri1After + day - lengthOfAdarIAndII - 208
|
|
||||||
else:
|
|
||||||
sdn = tishri1After + day - lengthOfAdarIAndII - 178
|
|
||||||
else:
|
|
||||||
# It is Adar II or later - don't need the year length.
|
|
||||||
(metonicCycle,metonicYear,moladDay,moladHalakim,tishri1After) = self.StartOfYear(year+1)
|
|
||||||
|
|
||||||
if month == 7:
|
|
||||||
sdn = tishri1After + day - 207
|
|
||||||
elif month == 8:
|
|
||||||
sdn = tishri1After + day - 178
|
|
||||||
elif month == 9:
|
|
||||||
sdn = tishri1After + day - 148
|
|
||||||
elif month == 10:
|
|
||||||
sdn = tishri1After + day - 119
|
|
||||||
elif month == 11:
|
|
||||||
sdn = tishri1After + day - 89
|
|
||||||
elif month == 12:
|
|
||||||
sdn = tishri1After + day - 60
|
|
||||||
elif month == 13:
|
|
||||||
sdn = tishri1After + day - 30
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
return sdn + Hebrew.SDN_OFFSET
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Persian
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
class Persian(Calendar):
|
|
||||||
"""Persian Calendar"""
|
|
||||||
|
|
||||||
EPOCH = 1948320.5
|
|
||||||
SDN_475_1_1 = 2121446
|
|
||||||
|
|
||||||
MONTHS = [ "Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad",
|
|
||||||
"Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand" ]
|
|
||||||
|
|
||||||
M2NUM = {
|
|
||||||
"farvardin" : 1, "ordibehesht" : 2, "khordad" : 3,
|
|
||||||
"tir" : 4, "mordad" : 5, "shahrivar" : 6,
|
|
||||||
"mehr" : 7, "aban" : 8, "azar" : 9,
|
|
||||||
"dey" : 10, "bahman" : 11, "esfand" : 12
|
|
||||||
}
|
|
||||||
|
|
||||||
NAME = "Persian"
|
|
||||||
TNAME = _("Persian")
|
|
||||||
|
|
||||||
def quote_display(self,year,month,day,mode):
|
|
||||||
return "%s (%s)" % (self.display(year,month,day,mode),Persian.NAME)
|
|
||||||
|
|
||||||
def set_month_string(self,text):
|
|
||||||
try:
|
|
||||||
return Persian.M2NUM[unicode(text.lower())]
|
|
||||||
except KeyError:
|
|
||||||
return UNDEF
|
|
||||||
|
|
||||||
def month(self,val):
|
|
||||||
try:
|
|
||||||
return Persian.MONTHS[val-1]
|
|
||||||
except:
|
|
||||||
return "Illegal Month"
|
|
||||||
|
|
||||||
def get_sdn(self,year, month, day):
|
|
||||||
if year >= 0:
|
|
||||||
epbase = year - 474
|
|
||||||
else:
|
|
||||||
epbase = year - 473
|
|
||||||
|
|
||||||
epyear = 474 + epbase % 2820
|
|
||||||
|
|
||||||
if month <= 7:
|
|
||||||
v1 = (month - 1) * 31
|
|
||||||
else:
|
|
||||||
v1 = ((month - 1) * 30) + 6
|
|
||||||
v2 = math.floor(((epyear * 682) - 110) / 2816)
|
|
||||||
v3 = (epyear - 1) * 365 + day
|
|
||||||
v4 = math.floor(epbase / 2820) * 1029983
|
|
||||||
|
|
||||||
return int(math.ceil(v1 + v2 + v3 + v4 + Persian.EPOCH - 1))
|
|
||||||
|
|
||||||
def get_ymd(self,sdn):
|
|
||||||
sdn = math.floor(sdn) + 0.5
|
|
||||||
|
|
||||||
depoch = sdn - self.get_sdn(475,1,1)
|
|
||||||
cycle = math.floor(depoch / 1029983)
|
|
||||||
cyear = depoch % 1029983
|
|
||||||
if cyear == 1029982:
|
|
||||||
ycycle = 2820
|
|
||||||
else:
|
|
||||||
aux1 = math.floor(cyear / 366)
|
|
||||||
aux2 = cyear % 366
|
|
||||||
ycycle = math.floor(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) + aux1 + 1;
|
|
||||||
|
|
||||||
year = ycycle + (2820 * cycle) + 474
|
|
||||||
if year <= 0:
|
|
||||||
year = year - 1;
|
|
||||||
|
|
||||||
yday = sdn - self.get_sdn(year, 1, 1) + 1
|
|
||||||
if yday < 186:
|
|
||||||
month = math.ceil(yday / 31)
|
|
||||||
else:
|
|
||||||
month = math.ceil((yday - 6) / 30)
|
|
||||||
day = (sdn - self.get_sdn(year, month, 1)) + 1
|
|
||||||
return (int(year), int(month), int(day))
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# FrenchRepublic
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
class FrenchRepublic(Calendar):
|
|
||||||
"""French Republic Calendar"""
|
|
||||||
|
|
||||||
SDN_OFFSET = 2375474
|
|
||||||
DAYS_PER_4_YEARS = 1461
|
|
||||||
DAYS_PER_MONTH = 30
|
|
||||||
FIRST_VALID = 2375840
|
|
||||||
LAST_VALID = 2380952
|
|
||||||
|
|
||||||
MONTHS = [
|
|
||||||
unicode("Vendémiaire",'latin-1'), unicode("Brumaire",'latin-1'),
|
|
||||||
unicode("Frimaire",'latin-1'), unicode("Nivôse",'latin-1'),
|
|
||||||
unicode("Pluviôse",'latin-1'), unicode("Ventôse",'latin-1'),
|
|
||||||
unicode("Germinal",'latin-1'), unicode("Floréal",'latin-1'),
|
|
||||||
unicode("Prairial",'latin-1'), unicode("Messidor",'latin-1'),
|
|
||||||
unicode("Thermidor",'latin-1'), unicode("Fructidor",'latin-1'),
|
|
||||||
unicode("Extra",'latin-1'),]
|
|
||||||
|
|
||||||
M2NUM = {
|
|
||||||
"vend" : 1, "brum" : 2, "frim" : 3, "nivo" : 4, "pluv" : 5, "vent" : 6,
|
|
||||||
"germ" : 7, "flor" : 8, "prai" : 9, "mess" :10, "ther" :11, "fruc" :12,
|
|
||||||
"extr" : 13,"comp" :13, unicode("nivô",'latin-1') : 4
|
|
||||||
}
|
|
||||||
|
|
||||||
NAME = "French Republican"
|
|
||||||
TNAME = _("French Republican")
|
|
||||||
|
|
||||||
def quote_display(self,year,month,day,mode):
|
|
||||||
return "%s (%s)" % (self.display(year,month,day,mode),FrenchRepublic.NAME)
|
|
||||||
|
|
||||||
def mlen(self):
|
|
||||||
return 4
|
|
||||||
|
|
||||||
def month(self,val):
|
|
||||||
try:
|
|
||||||
return FrenchRepublic.MONTHS[val-1]
|
|
||||||
except:
|
|
||||||
return "Illegal Month"
|
|
||||||
|
|
||||||
def set_month_string(self,text):
|
|
||||||
val = (unicode(text)[0:4]).lower()
|
|
||||||
try:
|
|
||||||
return FrenchRepublic.M2NUM[val]
|
|
||||||
except KeyError:
|
|
||||||
return UNDEF
|
|
||||||
|
|
||||||
def get_sdn(self,y,m,d):
|
|
||||||
"""Converts a French Republican Calendar date to an SDN number"""
|
|
||||||
if (y < 1 or y > 14 or m < 1 or m > 13 or d < 1 or d > 30):
|
|
||||||
return 0
|
|
||||||
return (y*FrenchRepublic.DAYS_PER_4_YEARS)/4 + \
|
|
||||||
(m-1)*FrenchRepublic.DAYS_PER_MONTH + \
|
|
||||||
d + FrenchRepublic.SDN_OFFSET
|
|
||||||
|
|
||||||
def get_ymd(self,sdn):
|
|
||||||
"""Converts an SDN number to a French Republican Calendar date"""
|
|
||||||
if (sdn < FrenchRepublic.FIRST_VALID or sdn > FrenchRepublic.LAST_VALID) :
|
|
||||||
return (0,0,0)
|
|
||||||
temp = (sdn-FrenchRepublic.SDN_OFFSET)*4 - 1
|
|
||||||
year = temp/FrenchRepublic.DAYS_PER_4_YEARS
|
|
||||||
dayOfYear = (temp%FrenchRepublic.DAYS_PER_4_YEARS)/4
|
|
||||||
month = (dayOfYear/FrenchRepublic.DAYS_PER_MONTH)+1
|
|
||||||
day = (dayOfYear%FrenchRepublic.DAYS_PER_MONTH)+1
|
|
||||||
return (year,month,day)
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Gregorian
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
class Gregorian(Calendar):
|
|
||||||
"""Gregorian Calendar"""
|
|
||||||
|
|
||||||
SDN_OFFSET = 32045
|
|
||||||
DAYS_PER_5_MONTHS = 153
|
|
||||||
DAYS_PER_4_YEARS = 1461
|
|
||||||
DAYS_PER_400_YEARS = 146097
|
|
||||||
|
|
||||||
NAME = "Gregorian"
|
|
||||||
TNAME = _("Gregorian")
|
|
||||||
|
|
||||||
def quote_display(self,year,month,day,mode):
|
|
||||||
return self.display(year,month,day,mode)
|
|
||||||
|
|
||||||
def mlen(self):
|
|
||||||
return 3
|
|
||||||
|
|
||||||
def get_ymd(self,sdn):
|
|
||||||
"""Converts an SDN number to a gregorial date"""
|
|
||||||
if sdn <= 0:
|
|
||||||
return (0,0,0)
|
|
||||||
|
|
||||||
temp = (Gregorian.SDN_OFFSET + sdn) * 4 - 1
|
|
||||||
|
|
||||||
# Calculate the century (year/100)
|
|
||||||
century = temp / Gregorian.DAYS_PER_400_YEARS
|
|
||||||
|
|
||||||
# Calculate the year and day of year (1 <= dayOfYear <= 366)
|
|
||||||
|
|
||||||
temp = ((temp % Gregorian.DAYS_PER_400_YEARS) / 4) * 4 + 3
|
|
||||||
year = (century * 100) + (temp / Gregorian.DAYS_PER_4_YEARS)
|
|
||||||
dayOfYear = (temp % Gregorian.DAYS_PER_4_YEARS) / 4 + 1
|
|
||||||
|
|
||||||
# Calculate the month and day of month
|
|
||||||
temp = dayOfYear * 5 - 3
|
|
||||||
month = temp / Gregorian.DAYS_PER_5_MONTHS
|
|
||||||
day = (temp % Gregorian.DAYS_PER_5_MONTHS) / 5 + 1
|
|
||||||
|
|
||||||
# Convert to the normal beginning of the year
|
|
||||||
if month < 10 :
|
|
||||||
month = month + 3
|
|
||||||
else:
|
|
||||||
year = year + 1
|
|
||||||
month = month - 9
|
|
||||||
|
|
||||||
# Adjust to the B.C./A.D. type numbering
|
|
||||||
|
|
||||||
year = year - 4800
|
|
||||||
if year <= 0:
|
|
||||||
year = year - 1
|
|
||||||
|
|
||||||
return (year,month,day)
|
|
||||||
|
|
||||||
def get_sdn(self,iyear,imonth,iday):
|
|
||||||
"""Converts a gregorian date to an SDN number"""
|
|
||||||
# check for invalid dates
|
|
||||||
if iyear==0 or iyear<-4714 or imonth<=0 or imonth>12 or iday<=0 or iday>31:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# check for dates before SDN 1 (Nov 25, 4714 B.C.)
|
|
||||||
if iyear == -4714:
|
|
||||||
if imonth < 11 or imonth == 11 and iday < 25:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if iyear < 0:
|
|
||||||
year = iyear + 4801
|
|
||||||
else:
|
|
||||||
year = iyear + 4800
|
|
||||||
|
|
||||||
# Adjust the start of the year
|
|
||||||
|
|
||||||
if imonth > 2:
|
|
||||||
month = imonth - 3
|
|
||||||
else:
|
|
||||||
month = imonth + 9
|
|
||||||
year = year - 1
|
|
||||||
|
|
||||||
return( ((year / 100) * Gregorian.DAYS_PER_400_YEARS) / 4
|
|
||||||
+ ((year % 100) * Gregorian.DAYS_PER_4_YEARS) / 4
|
|
||||||
+ (month * Gregorian.DAYS_PER_5_MONTHS + 2) / 5
|
|
||||||
+ iday
|
|
||||||
- Gregorian.SDN_OFFSET );
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Julian
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
class Julian(Calendar):
|
|
||||||
"""Julian calendar"""
|
|
||||||
|
|
||||||
SDN_OFFSET = 32083
|
|
||||||
DAYS_PER_5_MONTHS = 153
|
|
||||||
DAYS_PER_4_YEARS = 1461
|
|
||||||
|
|
||||||
NAME = "Julian"
|
|
||||||
TNAME = _("Julian")
|
|
||||||
|
|
||||||
def quote_display(self,year,month,day,mode):
|
|
||||||
return "%s (%s)" % (self.display(year,month,day,mode),Julian.NAME)
|
|
||||||
|
|
||||||
def mlen(self):
|
|
||||||
return 3
|
|
||||||
|
|
||||||
def get_ymd(self,sdn):
|
|
||||||
"""Converts an SDN number to a Julian date"""
|
|
||||||
if sdn <= 0 :
|
|
||||||
return (0,0,0)
|
|
||||||
|
|
||||||
temp = (sdn + Julian.SDN_OFFSET) * 4 - 1
|
|
||||||
|
|
||||||
# Calculate the year and day of year (1 <= dayOfYear <= 366)
|
|
||||||
year = temp / Julian.DAYS_PER_4_YEARS
|
|
||||||
dayOfYear = (temp % Julian.DAYS_PER_4_YEARS) / 4 + 1
|
|
||||||
|
|
||||||
# Calculate the month and day of month
|
|
||||||
temp = dayOfYear * 5 - 3;
|
|
||||||
month = temp / Julian.DAYS_PER_5_MONTHS;
|
|
||||||
day = (temp % Julian.DAYS_PER_5_MONTHS) / 5 + 1;
|
|
||||||
|
|
||||||
# Convert to the normal beginning of the year
|
|
||||||
if month < 10:
|
|
||||||
month = month + 3
|
|
||||||
else:
|
|
||||||
year = year + 1
|
|
||||||
month = month - 9
|
|
||||||
|
|
||||||
# Adjust to the B.C./A.D. type numbering
|
|
||||||
year = year - 4800
|
|
||||||
if year <= 0:
|
|
||||||
year = year - 1
|
|
||||||
|
|
||||||
return (year,month,day)
|
|
||||||
|
|
||||||
def get_sdn(self,iyear,imonth,iday):
|
|
||||||
"""Converts a Julian calendar date to an SDN number"""
|
|
||||||
|
|
||||||
# check for invalid dates
|
|
||||||
if iyear==0 or iyear<-4713 or imonth<=0 or imonth>12 or iday<=0 or iday>31:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# check for dates before SDN 1 (Jan 2, 4713 B.C.)
|
|
||||||
if iyear == -4713:
|
|
||||||
if imonth == 1 and iday == 1:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# Make year always a positive number
|
|
||||||
if iyear < 0:
|
|
||||||
year = iyear + 4801
|
|
||||||
else:
|
|
||||||
year = iyear + 4800
|
|
||||||
|
|
||||||
# Adjust the start of the year
|
|
||||||
if imonth > 2:
|
|
||||||
month = imonth - 3
|
|
||||||
else:
|
|
||||||
month = imonth + 9
|
|
||||||
year = year - 1
|
|
||||||
|
|
||||||
return (year*Julian.DAYS_PER_4_YEARS)/4 + \
|
|
||||||
(month*Julian.DAYS_PER_5_MONTHS+2)/5 + \
|
|
||||||
iday - Julian.SDN_OFFSET
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Islamic
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
class Islamic(Calendar):
|
|
||||||
"""Islamic calendar"""
|
|
||||||
|
|
||||||
EPOCH = 1948439.5
|
|
||||||
|
|
||||||
MONTHS = [
|
|
||||||
"Muharram", "Safar", "Rabi`al-Awwal", "Rabi`ath-Thani",
|
|
||||||
"Jumada l-Ula", "Jumada t-Tania", "Rajab", "Sha`ban",
|
|
||||||
"Ramadan", "Shawwal", "Dhu l-Qa`da", "Dhu l-Hijja"
|
|
||||||
]
|
|
||||||
|
|
||||||
M2NUM = {
|
|
||||||
"muharram" : 1, "safar" : 2, "rabi`al-awwal" : 3,
|
|
||||||
"rabi`ath-thani" : 4, "jumada l-ula" : 5 , "jumada t-tania" : 6,
|
|
||||||
"rajab" : 7, "sha`ban" : 8, "ramadan" : 9,
|
|
||||||
"shawwal" : 10, "dhu l-qa`da" : 11, "dhu l-hijja" : 12
|
|
||||||
}
|
|
||||||
|
|
||||||
NAME = "Islamic"
|
|
||||||
TNAME = _("Islamic")
|
|
||||||
|
|
||||||
def quote_display(self,year,month,day,mode):
|
|
||||||
return "%s (%s)" % (self.display(year,month,day,mode),Islamic.NAME)
|
|
||||||
|
|
||||||
def set_month_string(self,text):
|
|
||||||
try:
|
|
||||||
return Islamic.M2NUM[unicode(text.lower())]
|
|
||||||
except KeyError:
|
|
||||||
return UNDEF
|
|
||||||
|
|
||||||
def month(self,val):
|
|
||||||
try:
|
|
||||||
return Islamic.MONTHS[val-1]
|
|
||||||
except:
|
|
||||||
return "Illegal Month"
|
|
||||||
|
|
||||||
def get_sdn(self,year, month, day):
|
|
||||||
v1 = math.ceil(29.5 * (month - 1))
|
|
||||||
v2 = (year - 1) * 354
|
|
||||||
v3 = math.floor((3 + (11 *year)) / 30)
|
|
||||||
|
|
||||||
return int(math.ceil((day + v1 + v2 + v3 + Islamic.EPOCH) - 1))
|
|
||||||
|
|
||||||
def get_ymd(self,sdn):
|
|
||||||
sdn = math.floor(sdn) + 0.5
|
|
||||||
year = int(math.floor(((30*(sdn-Islamic.EPOCH))+10646)/10631))
|
|
||||||
month = int(min(12, math.ceil((sdn-(29+self.get_sdn(year,1,1)))/29.5) + 1))
|
|
||||||
day = int((sdn - self.get_sdn(year,month,1)) + 1)
|
|
||||||
return (year,month,day)
|
|
||||||
|
|
||||||
_FMT_FUNC = [
|
_FMT_FUNC = [
|
||||||
Calendar.format_mon_dd_year,
|
Calendar.format_mon_dd_year,
|
||||||
@ -1276,10 +551,4 @@ def calendar_names():
|
|||||||
list.sort()
|
list.sort()
|
||||||
return list
|
return list
|
||||||
|
|
||||||
register(Gregorian)
|
|
||||||
register(FrenchRepublic)
|
|
||||||
register(Julian)
|
|
||||||
register(Persian)
|
|
||||||
register(Hebrew)
|
|
||||||
register(Islamic)
|
|
||||||
|
|
||||||
|
79
src/Date.py
79
src/Date.py
@ -38,6 +38,11 @@ import time
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import Calendar
|
import Calendar
|
||||||
|
import Gregorian
|
||||||
|
import Julian
|
||||||
|
import Hebrew
|
||||||
|
import FrenchRepublic
|
||||||
|
|
||||||
from intl import gettext as _
|
from intl import gettext as _
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -48,10 +53,10 @@ from intl import gettext as _
|
|||||||
UNDEF = -999999
|
UNDEF = -999999
|
||||||
|
|
||||||
_calendar_val = [
|
_calendar_val = [
|
||||||
Calendar.Gregorian,
|
Gregorian.Gregorian,
|
||||||
Calendar.Julian,
|
Julian.Julian,
|
||||||
Calendar.Hebrew,
|
Hebrew.Hebrew,
|
||||||
Calendar.FrenchRepublic,
|
FrenchRepublic.FrenchRepublic,
|
||||||
]
|
]
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -88,7 +93,7 @@ class Date:
|
|||||||
self.stop = None
|
self.stop = None
|
||||||
self.range = 0
|
self.range = 0
|
||||||
self.text = ""
|
self.text = ""
|
||||||
self.calendar = Calendar.Gregorian()
|
self.calendar = Gregorian.Gregorian()
|
||||||
|
|
||||||
def get_calendar(self):
|
def get_calendar(self):
|
||||||
return self.calendar
|
return self.calendar
|
||||||
@ -242,8 +247,12 @@ class Date:
|
|||||||
return s.year==UNDEF and s.month==UNDEF and s.day==UNDEF and not self.text
|
return s.year==UNDEF and s.month==UNDEF and s.day==UNDEF and not self.text
|
||||||
|
|
||||||
def isValid(self):
|
def isValid(self):
|
||||||
return self.range != -1
|
if self.range == -1:
|
||||||
|
return 0
|
||||||
|
elif self.range:
|
||||||
|
return self.start.getValid() and self.stop.getValid()
|
||||||
|
return self.start.getValid()
|
||||||
|
|
||||||
def isRange(self):
|
def isRange(self):
|
||||||
return self.range == 1
|
return self.range == 1
|
||||||
|
|
||||||
@ -267,7 +276,7 @@ class SingleDate:
|
|||||||
self.day = UNDEF
|
self.day = UNDEF
|
||||||
self.year = UNDEF
|
self.year = UNDEF
|
||||||
self.mode = Calendar.EXACT
|
self.mode = Calendar.EXACT
|
||||||
self.calendar = Calendar.Gregorian()
|
self.calendar = Gregorian.Gregorian()
|
||||||
|
|
||||||
def setMode(self,val):
|
def setMode(self,val):
|
||||||
self.mode = self.calendar.set_mode_value(val)
|
self.mode = self.calendar.set_mode_value(val)
|
||||||
@ -316,7 +325,9 @@ class SingleDate:
|
|||||||
|
|
||||||
def getValid(self):
|
def getValid(self):
|
||||||
""" Returns true if any part of the date is valid"""
|
""" Returns true if any part of the date is valid"""
|
||||||
return self.year != UNDEF or self.month != UNDEF or self.day != UNDEF
|
if self.year == UNDEF and self.month == UNDEF and self.day == UNDEF:
|
||||||
|
return 1
|
||||||
|
return self.calendar.check(self.year,self.month,self.day)
|
||||||
|
|
||||||
def setMonthStr(self,text):
|
def setMonthStr(self,text):
|
||||||
self.calendar.set_month_string(text)
|
self.calendar.set_month_string(text)
|
||||||
@ -430,53 +441,3 @@ def compare_dates(f,s):
|
|||||||
return cmp(first.month,second.month)
|
return cmp(first.month,second.month)
|
||||||
else:
|
else:
|
||||||
return cmp(first.day,second.day)
|
return cmp(first.day,second.day)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
|
|
||||||
a = Date()
|
|
||||||
a.set("24 May 1961")
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
a.set(a.getDate())
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
|
|
||||||
a.set_calendar(Calendar.Julian)
|
|
||||||
print "Julian : ", a.getDate()
|
|
||||||
a.set(a.getDate())
|
|
||||||
print "Julian : ", a.getDate()
|
|
||||||
|
|
||||||
a.set_calendar(Calendar.Gregorian)
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
a.set(a.getDate())
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
|
|
||||||
a.set_calendar(Calendar.Hebrew)
|
|
||||||
print "Hebrew : ", a.getDate()
|
|
||||||
a.set(a.getDate())
|
|
||||||
print "Hebrew : ", a.getDate()
|
|
||||||
|
|
||||||
a.set_calendar(Calendar.Gregorian)
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
a.set(a.getDate())
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
|
|
||||||
a.set_calendar(Calendar.Persian)
|
|
||||||
print "Persian : ", a.getDate()
|
|
||||||
a.set(a.getDate())
|
|
||||||
print "Persian : ", a.getDate()
|
|
||||||
|
|
||||||
a.set_calendar(Calendar.Gregorian)
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
a.set(a.getDate())
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
|
|
||||||
a.set_calendar(Calendar.Islamic)
|
|
||||||
print "Islamic : ", a.getDate()
|
|
||||||
a.set(a.getDate())
|
|
||||||
print "Islamic : ", a.getDate()
|
|
||||||
|
|
||||||
a.set_calendar(Calendar.Gregorian)
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
a.set(a.getDate())
|
|
||||||
print "Gregorian : ", a.getDate()
|
|
||||||
|
|
||||||
|
109
src/FrenchRepublic.py
Normal file
109
src/FrenchRepublic.py
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#
|
||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2001 Donald N. Allingham
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
"""
|
||||||
|
Gregorian calendar module for GRAMPS.
|
||||||
|
|
||||||
|
The original algorithms for this module came from Scott E. Lee's
|
||||||
|
C implementation. The original C source can be found at Scott's
|
||||||
|
web site at http://www.scottlee.com
|
||||||
|
"""
|
||||||
|
|
||||||
|
__author__ = "Donald N. Allingham"
|
||||||
|
__version__ = "$Revision$"
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Gramps Modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
import Calendar
|
||||||
|
from intl import gettext as _
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# FrenchRepublic
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
class FrenchRepublic(Calendar.Calendar):
|
||||||
|
"""French Republic Calendar"""
|
||||||
|
|
||||||
|
SDN_OFFSET = 2375474
|
||||||
|
DAYS_PER_4_YEARS = 1461
|
||||||
|
DAYS_PER_MONTH = 30
|
||||||
|
FIRST_VALID = 2375840
|
||||||
|
LAST_VALID = 2380952
|
||||||
|
|
||||||
|
MONTHS = [
|
||||||
|
unicode("Vendémiaire",'latin-1'), unicode("Brumaire",'latin-1'),
|
||||||
|
unicode("Frimaire",'latin-1'), unicode("Nivôse",'latin-1'),
|
||||||
|
unicode("Pluviôse",'latin-1'), unicode("Ventôse",'latin-1'),
|
||||||
|
unicode("Germinal",'latin-1'), unicode("Floréal",'latin-1'),
|
||||||
|
unicode("Prairial",'latin-1'), unicode("Messidor",'latin-1'),
|
||||||
|
unicode("Thermidor",'latin-1'), unicode("Fructidor",'latin-1'),
|
||||||
|
unicode("Extra",'latin-1'),]
|
||||||
|
|
||||||
|
M2NUM = {
|
||||||
|
"vend" : 1, "brum" : 2, "frim" : 3, "nivo" : 4, "pluv" : 5, "vent" : 6,
|
||||||
|
"germ" : 7, "flor" : 8, "prai" : 9, "mess" :10, "ther" :11, "fruc" :12,
|
||||||
|
"extr" : 13,"comp" :13, unicode("nivô",'latin-1') : 4
|
||||||
|
}
|
||||||
|
|
||||||
|
NAME = "French Republican"
|
||||||
|
TNAME = _("French Republican")
|
||||||
|
|
||||||
|
def quote_display(self,year,month,day,mode):
|
||||||
|
return "%s (%s)" % (self.display(year,month,day,mode),FrenchRepublic.NAME)
|
||||||
|
|
||||||
|
def mlen(self):
|
||||||
|
return 4
|
||||||
|
|
||||||
|
def month(self,val):
|
||||||
|
try:
|
||||||
|
return FrenchRepublic.MONTHS[val-1]
|
||||||
|
except:
|
||||||
|
return "Illegal Month"
|
||||||
|
|
||||||
|
def set_month_string(self,text):
|
||||||
|
val = (unicode(text)[0:4]).lower()
|
||||||
|
try:
|
||||||
|
return FrenchRepublic.M2NUM[val]
|
||||||
|
except KeyError:
|
||||||
|
return UNDEF
|
||||||
|
|
||||||
|
def get_sdn(self,y,m,d):
|
||||||
|
"""Converts a French Republican Calendar date to an SDN number"""
|
||||||
|
if (y < 1 or y > 14 or m < 1 or m > 13 or d < 1 or d > 30):
|
||||||
|
return 0
|
||||||
|
return (y*FrenchRepublic.DAYS_PER_4_YEARS)/4 + \
|
||||||
|
(m-1)*FrenchRepublic.DAYS_PER_MONTH + \
|
||||||
|
d + FrenchRepublic.SDN_OFFSET
|
||||||
|
|
||||||
|
def get_ymd(self,sdn):
|
||||||
|
"""Converts an SDN number to a French Republican Calendar date"""
|
||||||
|
if (sdn < FrenchRepublic.FIRST_VALID or sdn > FrenchRepublic.LAST_VALID) :
|
||||||
|
return (0,0,0)
|
||||||
|
temp = (sdn-FrenchRepublic.SDN_OFFSET)*4 - 1
|
||||||
|
year = temp/FrenchRepublic.DAYS_PER_4_YEARS
|
||||||
|
dayOfYear = (temp%FrenchRepublic.DAYS_PER_4_YEARS)/4
|
||||||
|
month = (dayOfYear/FrenchRepublic.DAYS_PER_MONTH)+1
|
||||||
|
day = (dayOfYear%FrenchRepublic.DAYS_PER_MONTH)+1
|
||||||
|
return (year,month,day)
|
||||||
|
|
||||||
|
Calendar.register(FrenchRepublic)
|
132
src/Gregorian.py
Normal file
132
src/Gregorian.py
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
#
|
||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2001 Donald N. Allingham
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
"""
|
||||||
|
Gregorian calendar module for GRAMPS.
|
||||||
|
|
||||||
|
The original algorithms for this module came from Scott E. Lee's
|
||||||
|
C implementation. The original C source can be found at Scott's
|
||||||
|
web site at http://www.scottlee.com
|
||||||
|
"""
|
||||||
|
|
||||||
|
__author__ = "Donald N. Allingham"
|
||||||
|
__version__ = "$Revision$"
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Gramps Modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
import Calendar
|
||||||
|
from intl import gettext as _
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Gregorian
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
class Gregorian(Calendar.Calendar):
|
||||||
|
"""Gregorian Calendar"""
|
||||||
|
|
||||||
|
SDN_OFFSET = 32045
|
||||||
|
DAYS_PER_5_MONTHS = 153
|
||||||
|
DAYS_PER_4_YEARS = 1461
|
||||||
|
DAYS_PER_400_YEARS = 146097
|
||||||
|
|
||||||
|
NAME = "Gregorian"
|
||||||
|
TNAME = _("Gregorian")
|
||||||
|
|
||||||
|
def quote_display(self,year,month,day,mode):
|
||||||
|
return self.display(year,month,day,mode)
|
||||||
|
|
||||||
|
def mlen(self):
|
||||||
|
return 3
|
||||||
|
|
||||||
|
def get_ymd(self,sdn):
|
||||||
|
"""Converts an SDN number to a gregorial date"""
|
||||||
|
if sdn <= 0:
|
||||||
|
return (0,0,0)
|
||||||
|
|
||||||
|
temp = (Gregorian.SDN_OFFSET + sdn) * 4 - 1
|
||||||
|
|
||||||
|
# Calculate the century (year/100)
|
||||||
|
century = temp / Gregorian.DAYS_PER_400_YEARS
|
||||||
|
|
||||||
|
# Calculate the year and day of year (1 <= dayOfYear <= 366)
|
||||||
|
|
||||||
|
temp = ((temp % Gregorian.DAYS_PER_400_YEARS) / 4) * 4 + 3
|
||||||
|
year = (century * 100) + (temp / Gregorian.DAYS_PER_4_YEARS)
|
||||||
|
dayOfYear = (temp % Gregorian.DAYS_PER_4_YEARS) / 4 + 1
|
||||||
|
|
||||||
|
# Calculate the month and day of month
|
||||||
|
temp = dayOfYear * 5 - 3
|
||||||
|
month = temp / Gregorian.DAYS_PER_5_MONTHS
|
||||||
|
day = (temp % Gregorian.DAYS_PER_5_MONTHS) / 5 + 1
|
||||||
|
|
||||||
|
# Convert to the normal beginning of the year
|
||||||
|
if month < 10 :
|
||||||
|
month = month + 3
|
||||||
|
else:
|
||||||
|
year = year + 1
|
||||||
|
month = month - 9
|
||||||
|
|
||||||
|
# Adjust to the B.C./A.D. type numbering
|
||||||
|
|
||||||
|
year = year - 4800
|
||||||
|
if year <= 0:
|
||||||
|
year = year - 1
|
||||||
|
|
||||||
|
return (year,month,day)
|
||||||
|
|
||||||
|
def get_sdn(self,iyear,imonth,iday):
|
||||||
|
"""Converts a gregorian date to an SDN number"""
|
||||||
|
# check for invalid dates
|
||||||
|
if iyear==0 or iyear<-4714 or imonth<=0 or imonth>12 or iday<=0 or iday>31:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# check for dates before SDN 1 (Nov 25, 4714 B.C.)
|
||||||
|
if iyear == -4714:
|
||||||
|
if imonth < 11 or imonth == 11 and iday < 25:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if iyear < 0:
|
||||||
|
year = iyear + 4801
|
||||||
|
else:
|
||||||
|
year = iyear + 4800
|
||||||
|
|
||||||
|
# Adjust the start of the year
|
||||||
|
|
||||||
|
if imonth > 2:
|
||||||
|
month = imonth - 3
|
||||||
|
else:
|
||||||
|
month = imonth + 9
|
||||||
|
year = year - 1
|
||||||
|
|
||||||
|
return( ((year / 100) * Gregorian.DAYS_PER_400_YEARS) / 4
|
||||||
|
+ ((year % 100) * Gregorian.DAYS_PER_4_YEARS) / 4
|
||||||
|
+ (month * Gregorian.DAYS_PER_5_MONTHS + 2) / 5
|
||||||
|
+ iday
|
||||||
|
- Gregorian.SDN_OFFSET );
|
||||||
|
|
||||||
|
def check(self,year,month,day):
|
||||||
|
if year > 2100 or month > 12 or day > 31:
|
||||||
|
return 0
|
||||||
|
return 1
|
||||||
|
|
||||||
|
Calendar.register(Gregorian)
|
390
src/Hebrew.py
Normal file
390
src/Hebrew.py
Normal file
@ -0,0 +1,390 @@
|
|||||||
|
#
|
||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2001 Donald N. Allingham
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
"""
|
||||||
|
Gregorian calendar module for GRAMPS.
|
||||||
|
|
||||||
|
The original algorithms for this module came from Scott E. Lee's
|
||||||
|
C implementation. The original C source can be found at Scott's
|
||||||
|
web site at http://www.scottlee.com
|
||||||
|
"""
|
||||||
|
|
||||||
|
__author__ = "Donald N. Allingham"
|
||||||
|
__version__ = "$Revision$"
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Gramps Modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
import Calendar
|
||||||
|
from intl import gettext as _
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Hebrew calendar
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
class Hebrew(Calendar.Calendar):
|
||||||
|
"""Jewish Calendar"""
|
||||||
|
|
||||||
|
HALAKIM_PER_HOUR = 1080
|
||||||
|
HALAKIM_PER_DAY = 25920
|
||||||
|
HALAKIM_PER_LUNAR_CYCLE = ((29 * HALAKIM_PER_DAY) + 13753)
|
||||||
|
HALAKIM_PER_METONIC_CYCLE = (HALAKIM_PER_LUNAR_CYCLE * (12 * 19 + 7))
|
||||||
|
|
||||||
|
SDN_OFFSET = 347997
|
||||||
|
NEW_MOON_OF_CREATION = 31524
|
||||||
|
|
||||||
|
SUNDAY = 0
|
||||||
|
MONDAY = 1
|
||||||
|
TUESDAY = 2
|
||||||
|
WEDNESDAY= 3
|
||||||
|
FRIDAY = 5
|
||||||
|
|
||||||
|
NOON = (18 * HALAKIM_PER_HOUR)
|
||||||
|
AM3_11_20 = ((9 * HALAKIM_PER_HOUR) + 204)
|
||||||
|
AM9_32_43 = ((15 * HALAKIM_PER_HOUR) + 589)
|
||||||
|
|
||||||
|
monthsPerYear = [
|
||||||
|
12, 12, 13, 12, 12, 13, 12, 13, 12, 12,
|
||||||
|
13, 12, 12, 13, 12, 12, 13, 12, 13 ]
|
||||||
|
|
||||||
|
yearOffset = [
|
||||||
|
0, 12, 24, 37, 49, 61, 74, 86, 99, 111, 123,
|
||||||
|
136, 148, 160, 173, 185, 197, 210, 222 ]
|
||||||
|
|
||||||
|
MONTHS = [
|
||||||
|
"Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "AdarI",
|
||||||
|
"AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz", "Av",
|
||||||
|
"Elul",]
|
||||||
|
|
||||||
|
M2NUM = {
|
||||||
|
"tishri" : 1, "heshvan" : 2, "kislev" : 3, "tevet" : 4,
|
||||||
|
"shevat" : 5, "adari" : 6, "adarii" : 7, "nisan" : 8,
|
||||||
|
"iyyar" : 9, "sivan" :10, "tammuz" :11, "av" : 12,
|
||||||
|
"elul" : 13,"tsh" : 1, "csh" : 2, "ksl" : 3,
|
||||||
|
"tvt" : 4, "shv" : 5, "adr" : 6, "ads" : 7,
|
||||||
|
"nsn" : 8, "iyr" : 9, "svn" :10, "tmz" : 11,
|
||||||
|
"aav" :12, "ell" :13,
|
||||||
|
}
|
||||||
|
|
||||||
|
NAME = "Hebrew"
|
||||||
|
TNAME = _("Hebrew")
|
||||||
|
|
||||||
|
def quote_display(self,year,month,day,mode):
|
||||||
|
return "%s (%s)" % (self.display(year,month,day,mode),Hebrew.NAME)
|
||||||
|
|
||||||
|
def month(self,val):
|
||||||
|
try:
|
||||||
|
return Hebrew.MONTHS[val-1]
|
||||||
|
except:
|
||||||
|
return "Illegal Month"
|
||||||
|
|
||||||
|
def set_month_string(self,text):
|
||||||
|
try:
|
||||||
|
return Hebrew.M2NUM[unicode(text.lower())]
|
||||||
|
except KeyError:
|
||||||
|
return UNDEF
|
||||||
|
|
||||||
|
def Tishri1(self,metonicYear, moladDay, moladHalakim):
|
||||||
|
|
||||||
|
tishri1 = moladDay
|
||||||
|
dow = tishri1 % 7
|
||||||
|
leapYear = metonicYear in [ 2, 5, 7, 10, 13, 16, 18]
|
||||||
|
lastWasLeapYear = metonicYear in [ 3, 6, 8, 11, 14, 17, 0]
|
||||||
|
|
||||||
|
# Apply rules 2, 3 and 4.
|
||||||
|
if ((moladHalakim >= Hebrew.NOON) or
|
||||||
|
((not leapYear) and dow == Hebrew.TUESDAY and
|
||||||
|
moladHalakim >= Hebrew.AM3_11_20) or
|
||||||
|
(lastWasLeapYear and dow == Hebrew.MONDAY and moladHalakim >= Hebrew.AM9_32_43)) :
|
||||||
|
tishri1 = tishri1 + 1
|
||||||
|
dow = dow + 1
|
||||||
|
if dow == 7:
|
||||||
|
dow = 0
|
||||||
|
|
||||||
|
# Apply rule 1 after the others because it can cause an additional
|
||||||
|
# delay of one day
|
||||||
|
|
||||||
|
if dow == Hebrew.WEDNESDAY or dow == Hebrew.FRIDAY or dow == Hebrew.SUNDAY:
|
||||||
|
tishri1 = tishri1 + 1
|
||||||
|
|
||||||
|
return tishri1
|
||||||
|
|
||||||
|
def MoladOfMetonicCycle(self,metonicCycle):
|
||||||
|
|
||||||
|
# Start with the time of the first molad after creation.
|
||||||
|
|
||||||
|
r1 = Hebrew.NEW_MOON_OF_CREATION
|
||||||
|
|
||||||
|
# Calculate metonicCycle * HALAKIM_PER_METONIC_CYCLE. The upper 32
|
||||||
|
# bits of the result will be in r2 and the lower 16 bits will be
|
||||||
|
# in r1.
|
||||||
|
|
||||||
|
r1 = r1 + (metonicCycle * (Hebrew.HALAKIM_PER_METONIC_CYCLE & 0xFFFF))
|
||||||
|
r2 = r1 >> 16
|
||||||
|
r2 = r2 + (metonicCycle * ((Hebrew.HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF))
|
||||||
|
|
||||||
|
# Calculate r2r1 / HALAKIM_PER_DAY. The remainder will be in r1, the
|
||||||
|
# upper 16 bits of the quotient will be in d2 and the lower 16 bits
|
||||||
|
# will be in d1.
|
||||||
|
|
||||||
|
d2 = r2 / Hebrew.HALAKIM_PER_DAY
|
||||||
|
r2 = r2 - (d2 * Hebrew.HALAKIM_PER_DAY)
|
||||||
|
r1 = (r2 << 16) | (r1 & 0xFFFF)
|
||||||
|
d1 = r1 / Hebrew.HALAKIM_PER_DAY
|
||||||
|
r1 = r1 - ( d1 * Hebrew.HALAKIM_PER_DAY)
|
||||||
|
|
||||||
|
MoladDay = (d2 << 16) | d1
|
||||||
|
MoladHalakim = r1
|
||||||
|
|
||||||
|
return (MoladDay,MoladHalakim)
|
||||||
|
|
||||||
|
def TishriMolad(self,inputDay):
|
||||||
|
|
||||||
|
# Estimate the metonic cycle number. Note that this may be an under
|
||||||
|
# estimate because there are 6939.6896 days in a metonic cycle not
|
||||||
|
# 6940, but it will never be an over estimate. The loop below will
|
||||||
|
# correct for any error in this estimate. */
|
||||||
|
|
||||||
|
metonicCycle = (inputDay + 310) / 6940
|
||||||
|
|
||||||
|
# Calculate the time of the starting molad for this metonic cycle. */
|
||||||
|
|
||||||
|
(moladDay, moladHalakim) = self.MoladOfMetonicCycle(metonicCycle)
|
||||||
|
|
||||||
|
# If the above was an under estimate, increment the cycle number until
|
||||||
|
# the correct one is found. For modern dates this loop is about 98.6%
|
||||||
|
# likely to not execute, even once, because the above estimate is
|
||||||
|
# really quite close.
|
||||||
|
|
||||||
|
while moladDay < (inputDay - 6940 + 310):
|
||||||
|
metonicCycle = metonicCycle + 1
|
||||||
|
moladHalakim = moladHalakim + Hebrew.HALAKIM_PER_METONIC_CYCLE
|
||||||
|
moladDay = moladDay + ( moladHalakim / Hebrew.HALAKIM_PER_DAY)
|
||||||
|
moladHalakim = moladHalakim % Hebrew.HALAKIM_PER_DAY
|
||||||
|
|
||||||
|
# Find the molad of Tishri closest to this date.
|
||||||
|
|
||||||
|
for metonicYear in range(0,18):
|
||||||
|
if moladDay > inputDay - 74:
|
||||||
|
break
|
||||||
|
|
||||||
|
moladHalakim = moladHalakim + \
|
||||||
|
(Hebrew.HALAKIM_PER_LUNAR_CYCLE * Hebrew.monthsPerYear[metonicYear])
|
||||||
|
moladDay = moladDay + (moladHalakim / Hebrew.HALAKIM_PER_DAY)
|
||||||
|
moladHalakim = moladHalakim % Hebrew.HALAKIM_PER_DAY
|
||||||
|
else:
|
||||||
|
metonicYear = metonicYear + 1
|
||||||
|
return (metonicCycle, metonicYear, moladDay, moladHalakim)
|
||||||
|
|
||||||
|
def StartOfYear(self,year):
|
||||||
|
|
||||||
|
MetonicCycle = (year - 1) / 19;
|
||||||
|
MetonicYear = (year - 1) % 19;
|
||||||
|
(MoladDay, MoladHalakim) = self.MoladOfMetonicCycle(MetonicCycle)
|
||||||
|
|
||||||
|
MoladHalakim = MoladHalakim + (Hebrew.HALAKIM_PER_LUNAR_CYCLE * Hebrew.yearOffset[MetonicYear])
|
||||||
|
MoladDay = MoladDay + (MoladHalakim / Hebrew.HALAKIM_PER_DAY)
|
||||||
|
MoladHalakim = MoladHalakim % Hebrew.HALAKIM_PER_DAY
|
||||||
|
|
||||||
|
pTishri1 = self.Tishri1(MetonicYear, MoladDay, MoladHalakim);
|
||||||
|
|
||||||
|
return (MetonicCycle, MetonicYear, MoladDay, MoladHalakim, pTishri1)
|
||||||
|
|
||||||
|
def get_ymd(self,sdn):
|
||||||
|
"""Converts an SDN number to a Julian calendar date"""
|
||||||
|
|
||||||
|
if sdn <= Hebrew.SDN_OFFSET :
|
||||||
|
return (0,0,0)
|
||||||
|
|
||||||
|
inputDay = sdn - Hebrew.SDN_OFFSET
|
||||||
|
|
||||||
|
(metonicCycle, metonicYear, day, halakim) = self.TishriMolad(inputDay)
|
||||||
|
tishri1 = self.Tishri1(metonicYear, day, halakim);
|
||||||
|
|
||||||
|
if inputDay >= tishri1:
|
||||||
|
# It found Tishri 1 at the start of the year
|
||||||
|
|
||||||
|
Year = (metonicCycle * 19) + metonicYear + 1
|
||||||
|
if inputDay < tishri1 + 59:
|
||||||
|
if inputDay < tishri1 + 30:
|
||||||
|
Month = 1
|
||||||
|
Day = inputDay - tishri1 + 1
|
||||||
|
else:
|
||||||
|
Month = 2
|
||||||
|
Day = inputDay - tishri1 - 29
|
||||||
|
return (Year, Month, Day)
|
||||||
|
|
||||||
|
# We need the length of the year to figure this out, so find
|
||||||
|
# Tishri 1 of the next year. */
|
||||||
|
|
||||||
|
halakim = halakim + (Hebrew.HALAKIM_PER_LUNAR_CYCLE * Hebrew.monthsPerYear[metonicYear])
|
||||||
|
day = day + (halakim / Hebrew.HALAKIM_PER_DAY)
|
||||||
|
halakim = halakim % Hebrew.HALAKIM_PER_DAY;
|
||||||
|
tishri1After = self.Tishri1((metonicYear + 1) % 19, day, halakim);
|
||||||
|
else:
|
||||||
|
# It found Tishri 1 at the end of the year.
|
||||||
|
|
||||||
|
Year = metonicCycle * 19 + metonicYear
|
||||||
|
if inputDay >= tishri1 - 177:
|
||||||
|
# It is one of the last 6 months of the year.
|
||||||
|
if inputDay > tishri1 - 30:
|
||||||
|
Month = 13
|
||||||
|
Day = inputDay - tishri1 + 30
|
||||||
|
elif inputDay > tishri1 - 60:
|
||||||
|
Month = 12
|
||||||
|
Day = inputDay - tishri1 + 60
|
||||||
|
elif inputDay > tishri1 - 89:
|
||||||
|
Month = 11
|
||||||
|
Day = inputDay - tishri1 + 89
|
||||||
|
elif inputDay > tishri1 - 119:
|
||||||
|
Month = 10
|
||||||
|
Day = inputDay - tishri1 + 119
|
||||||
|
elif inputDay > tishri1 - 148:
|
||||||
|
Month = 9
|
||||||
|
Day = inputDay - tishri1 + 148
|
||||||
|
else:
|
||||||
|
Month = 8
|
||||||
|
Day = inputDay - tishri1 + 178
|
||||||
|
return (Year,Month,Day)
|
||||||
|
else:
|
||||||
|
if Hebrew.monthsPerYear[(Year - 1) % 19] == 13:
|
||||||
|
Month = 7
|
||||||
|
Day = inputDay - tishri1 + 207
|
||||||
|
if Day > 0:
|
||||||
|
return (Year,Month,Day)
|
||||||
|
Month = Month - 1
|
||||||
|
Day = Day + 30
|
||||||
|
if Day > 0:
|
||||||
|
return (Year,Month,Day)
|
||||||
|
Month = Month - 1
|
||||||
|
Day = Day + 30
|
||||||
|
else:
|
||||||
|
Month = 6
|
||||||
|
Day = inputDay - tishri1 + 207
|
||||||
|
if Day > 0:
|
||||||
|
return (Year,Month,Day)
|
||||||
|
Month = Month - 1
|
||||||
|
Day = Day + 30
|
||||||
|
|
||||||
|
if Day > 0:
|
||||||
|
return (Year,Month,Day)
|
||||||
|
Month = Month - 1
|
||||||
|
Day = Day + 29
|
||||||
|
if Day > 0:
|
||||||
|
return (Year,Month,Day)
|
||||||
|
|
||||||
|
# We need the length of the year to figure this out, so find
|
||||||
|
# Tishri 1 of this year
|
||||||
|
tishri1After = tishri1;
|
||||||
|
(metonicCycle,metonicYear,day,halakim) = self.TishriMolad(day-365)
|
||||||
|
tishri1 = self.Tishri1(metonicYear, day, halakim)
|
||||||
|
|
||||||
|
yearLength = tishri1After - tishri1;
|
||||||
|
cday = inputDay - tishri1 - 29;
|
||||||
|
if yearLength == 355 or yearLength == 385 :
|
||||||
|
# Heshvan has 30 days
|
||||||
|
if day <= 30:
|
||||||
|
Month = 2
|
||||||
|
Day = cday
|
||||||
|
return (Year,Month,Day)
|
||||||
|
day = day - 30
|
||||||
|
else:
|
||||||
|
# Heshvan has 29 days
|
||||||
|
if day <= 29:
|
||||||
|
Month = 2
|
||||||
|
Day = cday
|
||||||
|
return (Year,Month,Day)
|
||||||
|
|
||||||
|
cday = cday - 29
|
||||||
|
|
||||||
|
# It has to be Kislev
|
||||||
|
return (Year,3,cday)
|
||||||
|
|
||||||
|
def get_sdn(self,year, month, day):
|
||||||
|
"""Converts a Jewish calendar date to an SDN number"""
|
||||||
|
if year <= 0 or day <= 0 or day > 30 :
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if month == 1 or month == 2:
|
||||||
|
# It is Tishri or Heshvan - don't need the year length.
|
||||||
|
(metonicCycle,metonicYear,moladDay,moladHalakim,tishri1) = self.StartOfYear(year)
|
||||||
|
if month == 1:
|
||||||
|
sdn = tishri1 + day - 1
|
||||||
|
else:
|
||||||
|
sdn = tishri1 + day + 29
|
||||||
|
elif month == 3:
|
||||||
|
# It is Kislev - must find the year length.
|
||||||
|
|
||||||
|
# Find the start of the year.
|
||||||
|
(metonicCycle,metonicYear,moladDay,moladHalakim,tishri1) = self.StartOfYear(year)
|
||||||
|
|
||||||
|
# Find the end of the year.
|
||||||
|
moladHalakim = moladHalakim + (Hebrew.HALAKIM_PER_LUNAR_CYCLE*Hebrew.monthsPerYear[metonicYear])
|
||||||
|
moladDay = moladDay + (moladHalakim / Hebrew.HALAKIM_PER_DAY)
|
||||||
|
moladHalakim = moladHalakim % Hebrew.HALAKIM_PER_DAY
|
||||||
|
tishri1After = self.Tishri1((metonicYear + 1) % 19, moladDay, moladHalakim)
|
||||||
|
|
||||||
|
yearLength = tishri1After - tishri1
|
||||||
|
|
||||||
|
if yearLength == 355 or yearLength == 385:
|
||||||
|
sdn = tishri1 + day + 59
|
||||||
|
else:
|
||||||
|
sdn = tishri1 + day + 58
|
||||||
|
elif month == 4 or month == 5 or month == 6:
|
||||||
|
# It is Tevet, Shevat or Adar I - don't need the year length
|
||||||
|
|
||||||
|
(metonicCycle,metonicYear,moladDay,moladHalakim,tishri1After) = self.StartOfYear(year+1)
|
||||||
|
|
||||||
|
if Hebrew.monthsPerYear[(year - 1) % 19] == 12:
|
||||||
|
lengthOfAdarIAndII = 29
|
||||||
|
else:
|
||||||
|
lengthOfAdarIAndII = 59
|
||||||
|
|
||||||
|
if month == 4:
|
||||||
|
sdn = tishri1After + day - lengthOfAdarIAndII - 237
|
||||||
|
elif month == 5:
|
||||||
|
sdn = tishri1After + day - lengthOfAdarIAndII - 208
|
||||||
|
else:
|
||||||
|
sdn = tishri1After + day - lengthOfAdarIAndII - 178
|
||||||
|
else:
|
||||||
|
# It is Adar II or later - don't need the year length.
|
||||||
|
(metonicCycle,metonicYear,moladDay,moladHalakim,tishri1After) = self.StartOfYear(year+1)
|
||||||
|
|
||||||
|
if month == 7:
|
||||||
|
sdn = tishri1After + day - 207
|
||||||
|
elif month == 8:
|
||||||
|
sdn = tishri1After + day - 178
|
||||||
|
elif month == 9:
|
||||||
|
sdn = tishri1After + day - 148
|
||||||
|
elif month == 10:
|
||||||
|
sdn = tishri1After + day - 119
|
||||||
|
elif month == 11:
|
||||||
|
sdn = tishri1After + day - 89
|
||||||
|
elif month == 12:
|
||||||
|
sdn = tishri1After + day - 60
|
||||||
|
elif month == 13:
|
||||||
|
sdn = tishri1After + day - 30
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
return sdn + Hebrew.SDN_OFFSET
|
||||||
|
|
||||||
|
Calendar.register(Hebrew)
|
119
src/Julian.py
Normal file
119
src/Julian.py
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
#
|
||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2001 Donald N. Allingham
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
"""
|
||||||
|
Gregorian calendar module for GRAMPS.
|
||||||
|
|
||||||
|
The original algorithms for this module came from Scott E. Lee's
|
||||||
|
C implementation. The original C source can be found at Scott's
|
||||||
|
web site at http://www.scottlee.com
|
||||||
|
"""
|
||||||
|
|
||||||
|
__author__ = "Donald N. Allingham"
|
||||||
|
__version__ = "$Revision$"
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Gramps Modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
import Calendar
|
||||||
|
from intl import gettext as _
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Julian
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
class Julian(Calendar.Calendar):
|
||||||
|
"""Julian calendar"""
|
||||||
|
|
||||||
|
SDN_OFFSET = 32083
|
||||||
|
DAYS_PER_5_MONTHS = 153
|
||||||
|
DAYS_PER_4_YEARS = 1461
|
||||||
|
|
||||||
|
NAME = "Julian"
|
||||||
|
TNAME = _("Julian")
|
||||||
|
|
||||||
|
def quote_display(self,year,month,day,mode):
|
||||||
|
return "%s (%s)" % (self.display(year,month,day,mode),Julian.NAME)
|
||||||
|
|
||||||
|
def mlen(self):
|
||||||
|
return 3
|
||||||
|
|
||||||
|
def get_ymd(self,sdn):
|
||||||
|
"""Converts an SDN number to a Julian date"""
|
||||||
|
if sdn <= 0 :
|
||||||
|
return (0,0,0)
|
||||||
|
|
||||||
|
temp = (sdn + Julian.SDN_OFFSET) * 4 - 1
|
||||||
|
|
||||||
|
# Calculate the year and day of year (1 <= dayOfYear <= 366)
|
||||||
|
year = temp / Julian.DAYS_PER_4_YEARS
|
||||||
|
dayOfYear = (temp % Julian.DAYS_PER_4_YEARS) / 4 + 1
|
||||||
|
|
||||||
|
# Calculate the month and day of month
|
||||||
|
temp = dayOfYear * 5 - 3;
|
||||||
|
month = temp / Julian.DAYS_PER_5_MONTHS;
|
||||||
|
day = (temp % Julian.DAYS_PER_5_MONTHS) / 5 + 1;
|
||||||
|
|
||||||
|
# Convert to the normal beginning of the year
|
||||||
|
if month < 10:
|
||||||
|
month = month + 3
|
||||||
|
else:
|
||||||
|
year = year + 1
|
||||||
|
month = month - 9
|
||||||
|
|
||||||
|
# Adjust to the B.C./A.D. type numbering
|
||||||
|
year = year - 4800
|
||||||
|
if year <= 0:
|
||||||
|
year = year - 1
|
||||||
|
|
||||||
|
return (year,month,day)
|
||||||
|
|
||||||
|
def get_sdn(self,iyear,imonth,iday):
|
||||||
|
"""Converts a Julian calendar date to an SDN number"""
|
||||||
|
|
||||||
|
# check for invalid dates
|
||||||
|
if iyear==0 or iyear<-4713 or imonth<=0 or imonth>12 or iday<=0 or iday>31:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# check for dates before SDN 1 (Jan 2, 4713 B.C.)
|
||||||
|
if iyear == -4713:
|
||||||
|
if imonth == 1 and iday == 1:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# Make year always a positive number
|
||||||
|
if iyear < 0:
|
||||||
|
year = iyear + 4801
|
||||||
|
else:
|
||||||
|
year = iyear + 4800
|
||||||
|
|
||||||
|
# Adjust the start of the year
|
||||||
|
if imonth > 2:
|
||||||
|
month = imonth - 3
|
||||||
|
else:
|
||||||
|
month = imonth + 9
|
||||||
|
year = year - 1
|
||||||
|
|
||||||
|
return (year*Julian.DAYS_PER_4_YEARS)/4 + \
|
||||||
|
(month*Julian.DAYS_PER_5_MONTHS+2)/5 + \
|
||||||
|
iday - Julian.SDN_OFFSET
|
||||||
|
|
||||||
|
Calendar.register(Julian)
|
@ -1,5 +1,5 @@
|
|||||||
# This is the src level Makefile for Gramps
|
# This is the src level Makefile for Gramps
|
||||||
SUBDIRS = docgen filters plugins data po
|
SUBDIRS = docgen filters plugins data po calendars
|
||||||
|
|
||||||
# For intl. support, how do we compile?
|
# For intl. support, how do we compile?
|
||||||
GVFSINC = @GPREF@
|
GVFSINC = @GPREF@
|
||||||
|
@ -110,7 +110,7 @@ pyexecdir = @pyexecdir@
|
|||||||
pythondir = @pythondir@
|
pythondir = @pythondir@
|
||||||
|
|
||||||
# This is the src level Makefile for Gramps
|
# This is the src level Makefile for Gramps
|
||||||
SUBDIRS = docgen filters plugins data po
|
SUBDIRS = docgen filters plugins data po calendars
|
||||||
|
|
||||||
# For intl. support, how do we compile?
|
# For intl. support, how do we compile?
|
||||||
GVFSINC = @GPREF@
|
GVFSINC = @GPREF@
|
||||||
|
@ -402,6 +402,8 @@ class Gramps:
|
|||||||
Plugins.load_plugins(os.path.expanduser("~/.gramps/docgen"))
|
Plugins.load_plugins(os.path.expanduser("~/.gramps/docgen"))
|
||||||
Plugins.load_plugins(const.pluginsDir)
|
Plugins.load_plugins(const.pluginsDir)
|
||||||
Plugins.load_plugins(os.path.expanduser("~/.gramps/plugins"))
|
Plugins.load_plugins(os.path.expanduser("~/.gramps/plugins"))
|
||||||
|
Plugins.load_plugins(const.calendarDir)
|
||||||
|
Plugins.load_plugins(os.path.expanduser("~/.gramps/calendars"))
|
||||||
|
|
||||||
Plugins.build_report_menu(self.report_menu,self.menu_report)
|
Plugins.build_report_menu(self.report_menu,self.menu_report)
|
||||||
Plugins.build_tools_menu(self.tools_menu,self.menu_tools)
|
Plugins.build_tools_menu(self.tools_menu,self.menu_tools)
|
||||||
|
Loading…
Reference in New Issue
Block a user