2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2001 Donald N. Allingham
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
Gregorian calendar module for GRAMPS.
23
The original algorithms for this module came from Scott E. Lee's
24
C implementation. The original C source can be found at Scott's
25
web site at http://www.scottlee.com
28
__author__ = "Donald N. Allingham"
29
__version__ = "$Revision: 1.3 $"
31
#-------------------------------------------------------------------------
35
#-------------------------------------------------------------------------
38
#-------------------------------------------------------------------------
42
#-------------------------------------------------------------------------
44
from gettext import gettext as _
46
#-------------------------------------------------------------------------
50
#-------------------------------------------------------------------------
51
class Persian(Calendar.Calendar):
52
"""Persian Calendar"""
57
MONTHS = [ "Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad",
58
"Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand" ]
61
"farvardin" : 1, "ordibehesht" : 2, "khordad" : 3,
62
"tir" : 4, "mordad" : 5, "shahrivar" : 6,
63
"mehr" : 7, "aban" : 8, "azar" : 9,
64
"dey" : 10, "bahman" : 11, "esfand" : 12
70
def quote_display(self,year,month,day,mode):
71
return "%s (%s)" % (self.display(year,month,day,mode),Persian.NAME)
73
def set_month_string(self,text):
75
return Persian.M2NUM[unicode(text.lower())]
81
return Persian.MONTHS[val-1]
83
return "Illegal Month"
85
def get_sdn(self,year, month, day):
91
epyear = 474 + epbase % 2820
96
v1 = ((month - 1) * 30) + 6
97
v2 = math.floor(((epyear * 682) - 110) / 2816)
98
v3 = (epyear - 1) * 365 + day
99
v4 = math.floor(epbase / 2820) * 1029983
101
return int(math.ceil(v1 + v2 + v3 + v4 + Persian.EPOCH - 1))
103
def get_ymd(self,sdn):
104
sdn = math.floor(sdn) + 0.5
106
depoch = sdn - self.get_sdn(475,1,1)
107
cycle = math.floor(depoch / 1029983)
108
cyear = depoch % 1029983
112
aux1 = math.floor(cyear / 366)
114
ycycle = math.floor(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) + aux1 + 1;
116
year = ycycle + (2820 * cycle) + 474
120
yday = sdn - self.get_sdn(year, 1, 1) + 1
122
month = math.ceil(yday / 31)
124
month = math.ceil((yday - 6) / 30)
125
day = (sdn - self.get_sdn(year, month, 1)) + 1
126
return (int(year), int(month), int(day))
128
Calendar.register(Persian)