2004-09-17 09:00:04 +05:30
|
|
|
# -*- coding: iso-8859-1 -*-
|
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2004 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
|
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
"""
|
|
|
|
U.S English date display class. Should serve as the base class for all
|
|
|
|
localized tasks.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Donald N. Allingham"
|
|
|
|
__version__ = "$Revision$"
|
|
|
|
|
|
|
|
import Date
|
2004-09-18 05:22:09 +05:30
|
|
|
import locale
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
class DateDisplay:
|
|
|
|
"""
|
|
|
|
U.S English date display class.
|
|
|
|
"""
|
|
|
|
|
|
|
|
formats = (
|
2004-09-25 03:35:46 +05:30
|
|
|
"YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year",
|
2004-09-18 05:22:09 +05:30
|
|
|
"MON DAY, YEAR", "Day Month Year", "DAY MON YEAR"
|
2004-09-17 09:00:04 +05:30
|
|
|
)
|
|
|
|
|
2004-09-18 05:22:09 +05:30
|
|
|
calendar = (
|
|
|
|
""," (Julian)"," (Hebrew)"," (French Republican)",
|
|
|
|
" (Persian)"," (Islamic)"
|
2004-09-17 09:00:04 +05:30
|
|
|
)
|
|
|
|
|
2004-09-20 04:35:25 +05:30
|
|
|
_mod_str = ("","before ","after ","about ","","","")
|
|
|
|
|
|
|
|
_qual_str = ("","estimated ","calculated ")
|
2004-09-18 05:22:09 +05:30
|
|
|
|
|
|
|
# determine the code set returned by nl_langinfo
|
|
|
|
_codeset = locale.nl_langinfo(locale.CODESET)
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2004-09-18 05:22:09 +05:30
|
|
|
# get month information from nl_langinfo. Since nl_langinfo
|
|
|
|
# returns data in the code set specified by the user, and
|
|
|
|
# gnome wants unicode, we need to convert each string from
|
|
|
|
# the native code set into unicode
|
2004-09-17 09:00:04 +05:30
|
|
|
_months = (
|
|
|
|
"",
|
2004-09-18 05:22:09 +05:30
|
|
|
unicode(locale.nl_langinfo(locale.MON_1),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_2),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_3),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_4),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_5),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_6),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_7),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_8),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_9),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_10),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_11),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.MON_12),_codeset),
|
2004-09-17 09:00:04 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
_MONS = (
|
|
|
|
"",
|
2004-09-27 09:50:43 +05:30
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_1),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_2),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_3),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_4),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_5),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_6),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_7),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_8),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_9),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_10),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_11),_codeset),
|
|
|
|
unicode(locale.nl_langinfo(locale.ABMON_12),_codeset),
|
2004-09-17 09:00:04 +05:30
|
|
|
)
|
2004-09-25 03:35:46 +05:30
|
|
|
|
2004-09-27 08:46:48 +05:30
|
|
|
_tformat = locale.nl_langinfo(locale.D_FMT).replace('%y','%Y')
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
_hebrew = (
|
2004-09-18 05:22:09 +05:30
|
|
|
"", "Tishri", "Heshvan", "Kislev", "Tevet", "Shevat",
|
|
|
|
"AdarI", "AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz",
|
|
|
|
"Av", "Elul"
|
2004-09-17 09:00:04 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
_french = (
|
2004-09-24 03:02:07 +05:30
|
|
|
u'', u'Vend\xe9miaire', u'Brumaire',
|
|
|
|
u'Frimaire', u'Niv\xf4se', u'Pluvi\xf4se',
|
|
|
|
u'Vent\xf4se', u'Germinal', u'Flor\xe9al',
|
|
|
|
u'Prairial', u'Messidor', u'Thermidor',
|
|
|
|
u'Fructidor', u'Extra'
|
2004-09-17 09:00:04 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
_persian = (
|
2004-09-18 05:22:09 +05:30
|
|
|
"", "Farvardin", "Ordibehesht", "Khordad", "Tir",
|
|
|
|
"Mordad", "Shahrivar", "Mehr", "Aban", "Azar",
|
|
|
|
"Dey", "Bahman", "Esfand"
|
2004-09-17 09:00:04 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
_islamic = (
|
2004-09-18 05:22:09 +05:30
|
|
|
"", "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"
|
2004-09-17 09:00:04 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self,format=None):
|
|
|
|
"""
|
|
|
|
Creates a DateDisplay class that converts a Date object to a string
|
|
|
|
of the desired format. The format value must correspond to the format
|
|
|
|
list value (DateDisplay.format[]).
|
|
|
|
"""
|
2004-09-18 05:22:09 +05:30
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
self.verify_format(format)
|
|
|
|
if format == None:
|
|
|
|
self.format = 0
|
|
|
|
else:
|
|
|
|
self.format = format
|
2004-09-25 03:35:46 +05:30
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
self.display_cal = [
|
|
|
|
self._display_gregorian,
|
|
|
|
self._display_julian,
|
|
|
|
self._display_hebrew,
|
|
|
|
self._display_french,
|
|
|
|
self._display_persian,
|
|
|
|
self._display_islamic,
|
|
|
|
]
|
2004-09-18 05:22:09 +05:30
|
|
|
|
2004-09-26 08:38:53 +05:30
|
|
|
def set_format(self,format):
|
|
|
|
self.format = format
|
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
def verify_format(self,format):
|
|
|
|
"""
|
|
|
|
Verifies that the format value is within the correct range.
|
|
|
|
"""
|
2004-09-24 03:02:07 +05:30
|
|
|
pass
|
|
|
|
#assert(format < len(self.formats)-1)
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
def quote_display(self,date):
|
|
|
|
"""
|
|
|
|
Similar to the display task, except that if the value is a text only
|
|
|
|
value, it is enclosed in quotes.
|
|
|
|
"""
|
|
|
|
if date.get_modifier() == Date.MOD_TEXTONLY:
|
|
|
|
return '"%s"' % self.display(date)
|
|
|
|
else:
|
|
|
|
return self.display(date)
|
|
|
|
|
|
|
|
def text_display(self,date):
|
|
|
|
"""
|
|
|
|
Similar to the display task, except that if the value is a text only
|
|
|
|
value, it is enclosed in quotes.
|
|
|
|
"""
|
|
|
|
return date.get_text()
|
|
|
|
|
|
|
|
def display(self,date):
|
|
|
|
"""
|
|
|
|
Returns a text string representing the date.
|
|
|
|
"""
|
|
|
|
mod = date.get_modifier()
|
|
|
|
cal = date.get_calendar()
|
2004-09-20 04:35:25 +05:30
|
|
|
qual = date.get_quality()
|
2004-09-17 09:00:04 +05:30
|
|
|
start = date.get_start_date()
|
2004-09-20 04:35:25 +05:30
|
|
|
|
|
|
|
qual_str = self._qual_str[qual]
|
|
|
|
|
2004-10-03 04:37:43 +05:30
|
|
|
if mod == Date.MOD_TEXTONLY:
|
|
|
|
return date.get_text()
|
|
|
|
elif start == Date.EMPTY:
|
2004-09-17 09:00:04 +05:30
|
|
|
return u""
|
2004-10-03 04:37:43 +05:30
|
|
|
elif mod == Date.MOD_SPAN:
|
2004-09-17 09:00:04 +05:30
|
|
|
d1 = self.display_cal[cal](start)
|
|
|
|
d2 = self.display_cal[cal](date.get_stop_date())
|
2004-09-20 04:35:25 +05:30
|
|
|
return "%sfrom %s to %s%s" % (qual_str,d1,d2,self.calendar[cal])
|
2004-09-17 09:00:04 +05:30
|
|
|
elif mod == Date.MOD_RANGE:
|
|
|
|
d1 = self.display_cal[cal](start)
|
|
|
|
d2 = self.display_cal[cal](date.get_stop_date())
|
2004-09-20 04:35:25 +05:30
|
|
|
return "%sbetween %s and %s%s" % (qual_str,d1,d2,self.calendar[cal])
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
|
|
|
text = self.display_cal[date.get_calendar()](start)
|
2004-09-20 04:35:25 +05:30
|
|
|
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal])
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
def _slash_year(self,val,slash):
|
2004-10-16 10:40:35 +05:30
|
|
|
bc = ""
|
|
|
|
if val < 0:
|
|
|
|
val = - val
|
|
|
|
bc = " B.C.E"
|
|
|
|
|
2004-09-17 09:00:04 +05:30
|
|
|
if slash:
|
2004-10-16 10:40:35 +05:30
|
|
|
return "%d/%d%s" % (val,(val%10)+1,bc)
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-16 10:40:35 +05:30
|
|
|
return "%d%s" % (val,bc)
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
def _display_gregorian(self,date_val):
|
|
|
|
year = self._slash_year(date_val[2],date_val[3])
|
|
|
|
if self.format == 0:
|
|
|
|
# YYYY-MM-DD (ISO)
|
|
|
|
if date_val[0] == 0:
|
|
|
|
if date_val[1] == 0:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = year
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-12 01:54:33 +05:30
|
|
|
value = "%s-%02d" % (year,date_val[1])
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-12 01:54:33 +05:30
|
|
|
value = "%s-%02d-%02d" % (year,date_val[1],date_val[0])
|
2004-09-17 09:00:04 +05:30
|
|
|
elif self.format == 1:
|
2004-09-25 03:35:46 +05:30
|
|
|
if date_val[0] == 0 and date_val[1] == 0:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = str(date_val[2])
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = self._tformat.replace('%m',str(date_val[1]))
|
|
|
|
value = value.replace('%d',str(date_val[0]))
|
|
|
|
value = value.replace('%Y',str(date_val[2]))
|
2004-09-17 09:00:04 +05:30
|
|
|
elif self.format == 2:
|
|
|
|
# Month Day, Year
|
|
|
|
if date_val[0] == 0:
|
|
|
|
if date_val[1] == 0:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = year
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = "%s %s" % (self._months[date_val[1]],year)
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year)
|
2004-09-17 09:00:04 +05:30
|
|
|
elif self.format == 3:
|
|
|
|
# MON Day, Year
|
|
|
|
if date_val[0] == 0:
|
|
|
|
if date_val[1] == 0:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = year
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = "%s %s" % (self._MONS[date_val[1]],year)
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year)
|
2004-09-17 09:00:04 +05:30
|
|
|
elif self.format == 4:
|
|
|
|
# Day Month Year
|
|
|
|
if date_val[0] == 0:
|
|
|
|
if date_val[1] == 0:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = year
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = "%s %s" % (self._months[date_val[1]],year)
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = "%d %s %s" % (date_val[0],self._months[date_val[1]],year)
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
|
|
|
# Day MON Year
|
|
|
|
if date_val[0] == 0:
|
|
|
|
if date_val[1] == 0:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = year
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = "%s %s" % (self._MONS[date_val[1]],year)
|
2004-09-17 09:00:04 +05:30
|
|
|
else:
|
2004-10-04 02:34:54 +05:30
|
|
|
value = "%d %s %s" % (date_val[0],self._MONS[date_val[1]],year)
|
|
|
|
return value
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
def _display_julian(self,date_val):
|
|
|
|
# Julian date display is the same as Gregorian
|
|
|
|
return self._display_gregorian(date_val)
|
|
|
|
|
|
|
|
def _display_calendar(self,date_val,month_list):
|
|
|
|
year = date_val[2]
|
|
|
|
if self.format == 0 or self.format == 1:
|
|
|
|
# YYYY-MM-DD (ISO)
|
|
|
|
if date_val[0] == 0:
|
|
|
|
if date_val[1] == 0:
|
|
|
|
return year
|
|
|
|
else:
|
|
|
|
return "%d-%d" % (year,date_val[1])
|
|
|
|
else:
|
|
|
|
return "%d-%d-%d" % (year,date_val[1],date_val[0])
|
|
|
|
else:
|
|
|
|
if date_val[0] == 0:
|
|
|
|
if date_val[1] == 0:
|
|
|
|
return year
|
|
|
|
else:
|
|
|
|
return "%s %d" % (month_list[date_val[1]],year)
|
|
|
|
else:
|
|
|
|
return "%s %d, %s" % (month_list[date_val[1]],date_val[0],year)
|
|
|
|
|
|
|
|
def _display_french(self,date_val):
|
|
|
|
return self._display_calendar(date_val,self._french)
|
|
|
|
|
|
|
|
def _display_hebrew(self,date_val):
|
|
|
|
return self._display_calendar(date_val,self._hebrew)
|
|
|
|
|
|
|
|
def _display_persian(self,date_val):
|
|
|
|
return self._display_calendar(date_val,self._persian)
|
|
|
|
|
|
|
|
def _display_islamic(self,date_val):
|
|
|
|
return self._display_calendar(date_val,self._islamic)
|
|
|
|
|
2004-11-09 09:53:34 +05:30
|
|
|
class DateDisplayFR(DateDisplay):
|
|
|
|
|
|
|
|
calendar = (
|
|
|
|
u"", u" (Julien)", u" (H\xe9breu)",
|
|
|
|
u" (R\xe9volutionnaire)", u" (Perse)", u" (Islamique)"
|
|
|
|
)
|
|
|
|
|
|
|
|
_mod_str = (u"",u"avant ",u"apr\xe8s ",u"vers ",u"",u"",u"")
|
|
|
|
|
|
|
|
def display(self,date):
|
|
|
|
"""
|
|
|
|
Returns a text string representing the date.
|
|
|
|
"""
|
|
|
|
mod = date.get_modifier()
|
|
|
|
cal = date.get_calendar()
|
|
|
|
qual = date.get_quality()
|
|
|
|
start = date.get_start_date()
|
|
|
|
|
|
|
|
qual_str = self._qual_str[qual]
|
|
|
|
|
|
|
|
if mod == Date.MOD_TEXTONLY:
|
|
|
|
return date.get_text()
|
|
|
|
elif start == Date.EMPTY:
|
|
|
|
return u""
|
|
|
|
elif mod == Date.MOD_SPAN:
|
|
|
|
d1 = self.display_cal[cal](start)
|
|
|
|
d2 = self.display_cal[cal](date.get_stop_date())
|
|
|
|
return u"%sde %s \xe0 %s%s" % (qual_str,d1,d2,self.calendar[cal])
|
|
|
|
elif mod == Date.MOD_RANGE:
|
|
|
|
d1 = self.display_cal[cal](start)
|
|
|
|
d2 = self.display_cal[cal](date.get_stop_date())
|
|
|
|
return u"%sentre %s et %s%s" % (qual_str,d1,d2,self.calendar[cal])
|
|
|
|
else:
|
|
|
|
text = self.display_cal[date.get_calendar()](start)
|
|
|
|
return u"%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal])
|
|
|
|
|