diff --git a/gramps2/src/calendars/Islamic.py b/gramps2/src/calendars/Islamic.py new file mode 100644 index 000000000..d84a77606 --- /dev/null +++ b/gramps2/src/calendars/Islamic.py @@ -0,0 +1,94 @@ +# +# 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 _ + +#------------------------------------------------------------------------- +# +# Islamic +# +#------------------------------------------------------------------------- +class Islamic(Calendar.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) + +Calendar.register(Islamic) diff --git a/gramps2/src/calendars/Makefile.am b/gramps2/src/calendars/Makefile.am new file mode 100644 index 000000000..7ece44b9f --- /dev/null +++ b/gramps2/src/calendars/Makefile.am @@ -0,0 +1,8 @@ +# This is the src/plugins level Makefile for Gramps +# Use GNU make's ':=' syntax for nice wildcard use. +# If not using GNU make, then list all .py files individually +pkgpython_PYTHON := ${wildcard *.py} +pkgpyexecdir = @pkgpyexecdir@/plugins +pkgpythondir = @pkgpythondir@/plugins + +pkgdatadir = ${datadir}/@PACKAGE@/calendars diff --git a/gramps2/src/calendars/Persian.py b/gramps2/src/calendars/Persian.py new file mode 100644 index 000000000..ac8c8c1da --- /dev/null +++ b/gramps2/src/calendars/Persian.py @@ -0,0 +1,121 @@ +# +# 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 _ + +#------------------------------------------------------------------------- +# +# Persian +# +#------------------------------------------------------------------------- +class Persian(Calendar.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)) + +Calendar.register(Persian)