~rosco2/ubuntu/wily/gramps/bug-1492304

« back to all changes in this revision

Viewing changes to src/calendars/Islamic.py

  • Committer: Bazaar Package Importer
  • Author(s): James A. Treacy
  • Date: 2004-06-16 16:53:36 UTC
  • Revision ID: james.westby@ubuntu.com-20040616165336-kjzczqef4gnxrn2b
Tags: upstream-1.0.4
ImportĀ upstreamĀ versionĀ 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Gramps - a GTK+/GNOME based genealogy program
 
3
#
 
4
# Copyright (C) 2001  Donald N. Allingham
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
19
#
 
20
"""
 
21
Gregorian calendar module for GRAMPS. 
 
22
 
 
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
 
26
"""
 
27
 
 
28
__author__ = "Donald N. Allingham"
 
29
__version__ = "$Revision: 1.3 $"
 
30
 
 
31
#-------------------------------------------------------------------------
 
32
#
 
33
# python modules
 
34
#
 
35
#-------------------------------------------------------------------------
 
36
import math
 
37
 
 
38
#-------------------------------------------------------------------------
 
39
#
 
40
# Gramps Modules
 
41
#
 
42
#-------------------------------------------------------------------------
 
43
import Calendar
 
44
from gettext import gettext as _
 
45
 
 
46
#-------------------------------------------------------------------------
 
47
#
 
48
# Islamic
 
49
#
 
50
#-------------------------------------------------------------------------
 
51
class Islamic(Calendar.Calendar):
 
52
    """Islamic calendar"""
 
53
 
 
54
    EPOCH = 1948439.5
 
55
 
 
56
    MONTHS = [
 
57
        "Muharram",     "Safar",          "Rabi`al-Awwal", "Rabi`ath-Thani",
 
58
        "Jumada l-Ula", "Jumada t-Tania", "Rajab",         "Sha`ban",
 
59
        "Ramadan",      "Shawwal",        "Dhu l-Qa`da",   "Dhu l-Hijja"
 
60
        ]
 
61
 
 
62
    M2NUM = {
 
63
        "muharram" : 1,       "safar" : 2,         "rabi`al-awwal" : 3,
 
64
        "rabi`ath-thani" : 4, "jumada l-ula" : 5 , "jumada t-tania" : 6,
 
65
        "rajab" : 7,          "sha`ban" : 8,       "ramadan" : 9,
 
66
        "shawwal" : 10,       "dhu l-qa`da" : 11,  "dhu l-hijja" : 12
 
67
        }
 
68
 
 
69
    NAME = "Islamic"
 
70
    TNAME = _("Islamic")
 
71
 
 
72
    def quote_display(self,year,month,day,mode):
 
73
        return "%s (%s)" % (self.display(year,month,day,mode),Islamic.NAME)
 
74
 
 
75
    def set_month_string(self,text):
 
76
        try:
 
77
            return Islamic.M2NUM[unicode(text.lower())]
 
78
        except KeyError:
 
79
            return Calendar.UNDEF
 
80
 
 
81
    def month(self,val):
 
82
        try:
 
83
            return Islamic.MONTHS[val-1]
 
84
        except:
 
85
            return "Illegal Month"
 
86
 
 
87
    def get_sdn(self,year, month, day):
 
88
        v1 = math.ceil(29.5 * (month - 1))
 
89
        v2 = (year - 1) * 354
 
90
        v3 = math.floor((3 + (11 *year)) / 30)
 
91
 
 
92
        return int(math.ceil((day + v1 + v2 + v3 + Islamic.EPOCH) - 1))
 
93
 
 
94
    def get_ymd(self,sdn):
 
95
        sdn = math.floor(sdn) + 0.5
 
96
        year = int(math.floor(((30*(sdn-Islamic.EPOCH))+10646)/10631))
 
97
        month = int(min(12, math.ceil((sdn-(29+self.get_sdn(year,1,1)))/29.5) + 1))
 
98
        day = int((sdn - self.get_sdn(year,month,1)) + 1)
 
99
        return (year,month,day)
 
100
 
 
101
Calendar.register(Islamic)