From c440d722a6aa47f20e24aa5dd22ee6a09f84e5d4 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 7 Jan 2003 03:40:22 +0000 Subject: [PATCH] Calendar formats added svn: r1241 --- example/gramps/data.gramps | Bin 3767 -> 3823 bytes src/Calendar.py | 266 ++++++++++++++++++++++++++++++++----- src/Date.py | 262 ------------------------------------ src/GrampsCfg.py | 13 +- 4 files changed, 243 insertions(+), 298 deletions(-) diff --git a/example/gramps/data.gramps b/example/gramps/data.gramps index 5bd977f4aa061c7f3d28212d53bf084eac4f6659..d9f256923b82d965185dfaaebc421d58f294d021 100644 GIT binary patch literal 3823 zcmViKE1JxaCZ`(NXdw&Jb9}agwZ0q5daB21uH))z}njqf2MR7PR z7>SPAN~A!^N&W9{NJ+L7hcYdzJ{$_PvPjO5GsAh3>gg{(q7Xe3kx0dtFO@I4(e~AK|;zyhiH2XUH?eZ3No&=8Kq!*+?2mSj$(6#7s_70)b1;GIk@)3Uc zg5Z<{5(atS8KRr>FUYYhx3j@#^}L?djRl!>P)v9nLdU_dgXTD*AtedSXw*RoUkYFT z7(lNOt4C+h>F0O^NeCAHqClLzVmKma7yJ>;BAPBv`^BqL7aRoQ%(g5v>!Djr8JeX% z)loH+I{GwSoy}rF+0&eoFi@S;%TlK#g>{~NAus4F7vEKv>{S^MU$RuJ&VHYrXE5^L zr7kgtQQ?{GxPzhUlfNi;S#Ud68tma5qSYB zksc$d8j*F#sMxQP@wC6;&X*S5NjTgX(lG%0FGkoo)0y*=18o%R*zHxYdRk*`7I zIpeP7b}dJX$kpSCv4Ec-rmE+aZLfDgKjXq%Eb+Eja@&+8Q-SFdx+f_SI?iNUtsSO# zBiQ;`Pdo>lT9P?>lKBf727I1VY+^vLwPd$Iu*={DxOGeY1ty_6$)G9Icrfd1<})X1j!9! zJKtZ%I0aKuK?izO&{)1coAG)20{aGCvM0)jl-zQ&0glUH>2ITe6$#9q2m;+KQc2vg z2Zk!;v3#D?kl0v}JPAT-nE47vc~uv^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xK-Cxa$8x5I?*kE$qq~!<)FNv1!TrD5f>+?fq#7tRzidB%5OX!5380H z*OJ@|w4Ik}znYG%pfe`C5GR*GOxm=ppJ=IHt*=WA%a0G&Wfk!QrnV${E1ZQO0raUQK3OftpG_NMFdJoXX#1Lt!_%FcfIm*O>V{aW?4uOsxUIG00lmKQkIU>vR~T;kOe z=J63aO>jzLyaT6b{op6sFwp+k!kiBUygU`mZ=$`~y|{;N<$ri?qF(wx>mVd$p#8u3OV}U(x4k ze@Y8krzY#@k%hRbLZbX=VGC)yCT(kxKCQn&BNOPC2wF8kON(IR%MZ<79uFI{;`pAi h?_%=RbEN)Vr-@GeQlsJVaPxmZ{127x!Bt3N0042^P1^tf diff --git a/src/Calendar.py b/src/Calendar.py index 5fccb6543..5b6cdb655 100644 --- a/src/Calendar.py +++ b/src/Calendar.py @@ -70,6 +70,22 @@ fmt5 = re.compile(_start+"(\d+)\s*$", re.IGNORECASE) fmt6 = re.compile(_start+"(\S+)\s*$", re.IGNORECASE) +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def set_format_code(code): + Calendar.FORMATCODE = code + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def get_format_code(): + return Calendar.FORMATCODE + #------------------------------------------------------------------------- # # Calendar - base calendar @@ -77,7 +93,8 @@ fmt6 = re.compile(_start+"(\S+)\s*$", re.IGNORECASE) #------------------------------------------------------------------------- class Calendar: - entryCode = 0 + ENTRYCODE = 0 + FORMATCODE = 0 MONTHS = [ _("January"), _("February"), _("March"), _("April"), @@ -143,6 +160,9 @@ class Calendar: def quote_display(self,year,month,day,mode): return "%s (%s)" % (text,Calendar.NAME) + def display(self,year,month,day,mode): + return _FMT_FUNC[Calendar.FORMATCODE](self,year,month,day,mode) + def format_yymmdd(self,year,month,day,mode): if month == UNDEF and day == UNDEF and year == UNDEF : return "" @@ -160,13 +180,62 @@ class Calendar: retval = "????-%02d-%02d" % (month,day) else: retval = "%04d-%02d-%02d" % (year,month,day) + return self.fmt_mode(retval,mode) - if Calendar.MODE.has_key(mode): - return "%s %s" % (Calendar.MODE[mode],retval) + def format_mon_dd_year(self,year,month,day,mode): + """ + Formats the date in the form of DD Month Year, such as + January 20, 2000 + """ + if month == UNDEF and day == UNDEF and year == UNDEF: + return "" + elif day == UNDEF: + if month == UNDEF: + retval = str(year) + elif year == UNDEF: + retval = self.month(month) + else: + retval = "%s %d" % (self.month(month),year) + elif month == UNDEF: + retval = str(year) else: - return retval + if year == UNDEF: + retval = "%s %d, ????" % (self.month(month),day) + else: + retval = "%s %d, %d" % (self.month(month),day,year) - def display(self,year,month,day,mode): + return self.fmt_mode(retval,mode) + + + def format_MON_dd_year(self,year,month,day,mode): + """ + Formats the date in the form of DD Month Year, such as + January 20, 2000 + """ + if month == UNDEF and day == UNDEF and year == UNDEF: + return "" + elif day == UNDEF: + if month == UNDEF: + retval = str(year) + elif year == UNDEF: + retval = self.month(month).upper()[0:3] + else: + retval = "%s %d" % (self.month(month).upper()[0:3],year) + elif month == UNDEF: + retval = str(year) + else: + if year == UNDEF: + retval = "%s %d, ????" % (self.month(month).upper()[0:3],day) + else: + retval = "%s %d, %d" % (self.month(month).upper()[0:3],day,year) + + return self.fmt_mode(retval,mode) + + def format_dd_mon_year(self,year,month,day,mode): + """ + Formats the date in the form of DD Month Year, such as + 20 January 2000 + """ if year==UNDEF: if month == UNDEF: d = "" @@ -181,10 +250,154 @@ class Calendar: else: d = "%02d %s %d" % (day,self.month(month),year) - if Calendar.MODE.has_key(mode): - return "%s %s" % (Calendar.MODE[mode],d) + return self.fmt_mode(d,mode) + + def format_dd_MON_year(self,year,month,day,mode): + """ + Formats the date in the form of DD. Month Year, such as + 20. January 2000 + """ + if month == UNDEF and day == UNDEF and year == UNDEF : + return "" + elif day == UNDEF: + if month == UNDEF: + retval = str(year) + elif year == UNDEF: + retval = self.month(month).upper()[0:3] + else: + retval = "%s %d" % (self.month(month).upper()[0:3],year) + elif month == UNDEF: + retval = str(year) else: - return d + month_str = self.month(month).upper()[0:3] + if self.year == UNDEF: + retval = "%d %s ????" % (day,month_str) + else: + retval = "%d %s %d" % (day,month_str,year) + + return self.fmt_mode(retval,mode) + + def format_dd_dot_MON_year(self,year,month,day,mode): + """ + Formats the date in the form of DD. Month Year, such as + 20. January 2000 + """ + if month == UNDEF and day == UNDEF and year == UNDEF : + return "" + elif day == UNDEF: + if month == UNDEF: + retval = str(year) + elif year == UNDEF: + retval = self.month(month).upper()[0:3] + else: + retval = "%s %d" % (self.month(month).upper()[0:3],year) + elif month == UNDEF: + retval = str(year) + else: + month_str = self.month(month).upper()[0:3] + if self.year == UNDEF: + retval = "%d. %s ????" % (day,month_str) + else: + retval = "%d. %s %d" % (day,month_str,year) + + return self.fmt_mode(retval,mode) + + def format4(self,year,month,day,mode): + return self._get_mmddyyyy(year,month,day,mode,"/") + + def format5(self,year,month,day,mode): + return self._get_mmddyyyy(year,month,day,mode,"-") + + def format6(self,year,month,day,mode): + return self._get_ddmmyyyy(year,month,day,mode,"/") + + def format7(self,year,month,day,mode): + return self._get_ddmmyyyy(year,month,day,mode,"-") + + def format8(self,year,month,day,mode): + return self._get_mmddyyyy(year,month,day,mode,".") + + def format9(self,year,month,day,mode): + return self._get_ddmmyyyy(year,month,day,mode,".") + + def format11(self,year,month,day,mode): + return self._get_yyyymmdd(year,month,day,mode,"/") + + def format12(self,year,month,day,mode): + return self._get_yyyymmdd(year,month,day,mode,"-") + + def format13(self,year,month,day,mode): + return self._get_yyyymmdd(year,month,day,mode,".") + + def _get_mmddyyyy(self,year,month,day,mode,sep): + if month == UNDEF and day == UNDEF and year == UNDEF : + return "" + elif day == UNDEF: + if month == UNDEF: + retval = str(year) + elif year == UNDEF: + retval = "%02d%s??%s??" % (month+1,sep,sep) + else: + retval = "%02d%s??%s%04d" % (month+1,sep,sep,year) + elif month == UNDEF: + retval = "??%s%02d%s%04d" % (sep,day,sep,year) + else: + if year == UNDEF: + retval = "%02d%s%02d%s????" % (month+1,sep,day,sep) + else: + retval = "%02d%s%02d%s%04d" % (month+1,sep,day,sep,year) + + return self.fmt_mode(retval,mode) + + def _get_yyyymmdd(self,year,month,day,mode,sep): + retval = "" + + if month == UNDEF and day == UNDEF and year == UNDEF : + pass + elif day == UNDEF: + if month == UNDEF: + retval = str(self.year) + elif year == UNDEF: + retval = "????%s%02d%s??" % (sep,month+1,sep) + else: + retval = "%04d%s%02d" % (year,sep,month+1) + elif month == UNDEF: + retval = "%04d%s??%s%02d" % (year,sep,sep,day) + else: + if year == UNDEF: + retval = "????%s%02d%s%02d" % (sep,month+1,sep,day) + else: + retval = "%02d%s%02d%s%02d" % (year,sep,month+1,sep,day) + + return self.fmt_mode(retval,mode) + + def _get_ddmmyyyy(self,year,month,day,mode,sep): + retval = "" + + if month == UNDEF and day == UNDEF and year == UNDEF : + pass + elif day == UNDEF: + if month == UNDEF: + retval = str(year) + elif year == UNDEF: + retval = "??%s%02d%s??" % (sep,month+1,sep) + else: + retval = "??%s%02d%s%04d" % (sep,month+1,sep,year) + elif month == UNDEF: + retval = "%02d%s??%s%04d" % (day,sep,sep,year) + else: + if year == UNDEF: + retval = "%02d%s%02d%s????" % (day,sep,month+1,sep) + else: + retval = "%02d%s%02d%s%04d" % (day,sep,month+1,sep,year) + + return self.fmt_mode(retval,mode) + + def fmt_mode(self,val,mode): + if Calendar.MODE.has_key(mode): + return "%s %s" % (Calendar.MODE[mode],val) + else: + return val def get_ymd(self,val): return (0,0,0) @@ -1024,6 +1237,21 @@ class Islamic(Calendar): day = int((sdn - self.get_sdn(year,month,1)) + 1) return (year,month,day) +_FMT_FUNC = [ + Calendar.format_mon_dd_year, + Calendar.format_MON_dd_year, + Calendar.format_dd_MON_year, + Calendar.format4, + Calendar.format5, + Calendar.format6, + Calendar.format7, + Calendar.format9, + Calendar.format_dd_dot_MON_year, + Calendar.format11, + Calendar.format12, + Calendar.format13, + ] + #------------------------------------------------------------------------- # # Calendar registration @@ -1055,25 +1283,3 @@ register(Persian) register(Hebrew) register(Islamic) -if __name__ == "__main__": - - e = Gregorian() - print e.get_ymd(e.get_sdn(1992,12,2)), e.display(1992,12,2,EXACT) - - a = Julian() - print a.get_ymd(a.get_sdn(2002,1,28)), a.display(2002,1,28,ABOUT) - - f = Hebrew() - print f.get_ymd(f.get_sdn(1992,12,2)), f.display(1992,12,2,EXACT) - - e = Gregorian() - print e.get_ymd(e.get_sdn(1992,12,2)), e.display(1992,12,2,EXACT) - - g = Islamic() - print g.get_ymd(g.get_sdn(1992,12,2)), g.display(1992,12,2,EXACT) - - h = Persian() - print h.get_ymd(h.get_sdn(1992,12,2)), h.display(1992,12,2,EXACT) - - i = FrenchRepublic() - print i.get_ymd(i.get_sdn(1992,12,2)), i.display(1992,12,2,EXACT) diff --git a/src/Date.py b/src/Date.py index ec35a1101..bc92542d1 100644 --- a/src/Date.py +++ b/src/Date.py @@ -247,24 +247,6 @@ class Date: def isRange(self): return self.range == 1 -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def set_format_code(code): - global _func - Date.formatCode = code - _func = SingleDate.fmtFunc[code] - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def get_format_code(): - return Date.formatCode - #------------------------------------------------------------------------- # # @@ -360,248 +342,6 @@ class SingleDate: d = "-%02d" % self.day return "%s%s%s" % (y,m,d) - def _format1(self): - if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF: - return "" - elif self.day == UNDEF: - if self.month == UNDEF: - retval = str(self.year) - elif self.year == UNDEF: - retval = _mname[self.month] - else: - try: - retval = "%s %d" % (_mname[self.month],self.year) - except: - retval = "**** %d %d %d ****" % (self.year,self.month,self.day) - elif self.month == UNDEF: - retval = str(self.year) - else: - try: - month = _mname[self.month] - except: - month = "" - if self.year == UNDEF: - retval = "%s %d, ????" % (month,self.day) - else: - retval = "%s %d, %d" % (month,self.day,self.year) - - if self.mode == Calendar.ABOUT: - retval = _("about") + ' ' + retval - elif self.mode == Calendar.BEFORE: - retval = _("before") + ' ' + retval - elif self.mode == Calendar.AFTER: - retval = _("after") + ' ' + retval - return retval - - def _format2(self): - if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF : - return "" - elif self.month != UNDEF and self.month != UNDEF: - month = _mname[self.month] - if self.year == UNDEF: - retval = "%s %d, ????" % (string.upper(month[0:3]),self.day) - else: - retval = "%s %d, %d" % (string.upper(month[0:3]),self.day,self.year) - elif self.day == UNDEF: - if self.month == UNDEF: - retval = str(self.year) - elif self.year == UNDEF: - month = _mname[self.month] - retval = string.upper(month[0:3]) - else: - month = _mname[self.month] - retval = "%s %d" % (string.upper(month[0:3]),self.year) - else: - retval = str(self.year) - - if self.mode == Calendar.ABOUT: - retval = "%s %s" % (_("abt"),retval) - elif self.mode == Calendar.BEFORE: - retval = "%s %s" % (_("before"),retval) - elif self.mode == Calendar.AFTER: - retval = "%s %s" % (_("after"),retval) - - return retval - - def _format3(self): - if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF : - return "" - elif self.day == UNDEF: - if self.month == UNDEF: - retval = str(self.year) - elif self.year == UNDEF: - month = _mname[self.month] - retval = string.upper(month[0:3]) - else: - month = _mname[self.month] - retval = "%s %d" % (string.upper(month[0:3]),self.year) - elif self.month == UNDEF: - retval = str(self.year) - else: - month = _mname[self.month] - if self.year == UNDEF: - retval = "%d %s ????" % (self.day,string.upper(month[0:3])) - else: - retval = "%d %s %d" % (self.day,string.upper(month[0:3]),self.year) - - if self.mode == Calendar.ABOUT: - retval = "%s %s" % (_("ABOUT"),retval) - elif self.mode == Calendar.BEFORE: - retval = "%s %s" % (_("BEFORE"),retval) - elif self.mode == Calendar.AFTER: - retval = "%s %s" % (_("AFTER"),retval) - return retval - - def _format10(self): - if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF : - return "" - elif self.day == UNDEF: - if self.month == UNDEF: - retval = str(self.year) - elif self.year == UNDEF: - retval = _mname[self.month] - else: - month = _mname[self.month] - retval = "%s %d" % (month,self.year) - elif self.month == UNDEF: - retval = str(self.year) - else: - month = _mname[self.month] - if self.year == UNDEF: - retval = "%d. %s ????" % (self.day,month) - else: - retval = "%d. %s %d" % (self.day,month,self.year) - - if self.mode == Calendar.ABOUT: - retval = "%s %s" % (_("ABOUT"),retval) - elif self.mode == Calendar.BEFORE: - retval = "%s %s" % (_("BEFORE"),retval) - elif self.mode == Calendar.AFTER: - retval = "%s %s" % (_("AFTER"),retval) - - return retval - - def _get_mmddyyyy(self,sep): - if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF : - return "" - elif self.day == UNDEF: - if self.month == UNDEF: - retval = str(self.year) - elif self.year == UNDEF: - retval = "%02d%s??%s??" % (self.month+1,sep,sep) - else: - retval = "%02d%s??%s%04d" % (self.month+1,sep,sep,self.year) - elif self.month == UNDEF: - retval = "??%s%02d%s%04d" % (sep,self.day,sep,self.year) - else: - if self.year == UNDEF: - retval = "%02d%s%02d%s????" % (self.month+1,sep,self.day,sep) - else: - retval = "%02d%s%02d%s%04d" % (self.month+1,sep,self.day,sep,self.year) - - if self.mode == Calendar.ABOUT: - retval = "%s %s" % (_("ABOUT"),retval) - elif self.mode == Calendar.BEFORE: - retval = "%s %s" % (_("BEFORE"),retval) - elif self.mode == Calendar.AFTER: - retval = "%s %s" % (_("AFTER"),retval) - - return retval - - def _get_yyyymmdd(self,sep): - retval = "" - - if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF : - pass - elif self.day == UNDEF: - if self.month == UNDEF: - retval = str(self.year) - elif self.year == UNDEF: - retval = "????%s%02d%s??" % (sep,self.month+1,sep) - else: - retval = "%04d%s%02d" % (self.year,sep,self.month+1) - elif self.month == UNDEF: - retval = "%04d%s??%s%02d" % (self.year,sep,sep,self.day) - else: - if self.year == UNDEF: - retval = "????%s%02d%s%02d" % (sep,self.month+1,sep,self.day) - else: - retval = "%02d%s%02d%s%02d" % (self.year,sep,self.month+1,sep,self.day) - - if self.mode == Calendar.ABOUT: - retval = "%s %s" % (_("about"),retval) - - if self.mode == Calendar.BEFORE: - retval = "%s %s" % (_("before"),retval) - elif self.mode == Calendar.AFTER: - retval = "%s %s" % (_("after"),retval) - - return retval - - def _format4(self): - return self._get_mmddyyyy("/") - - def _format5(self): - return self._get_mmddyyyy("-") - - def _format8(self): - return self._get_mmddyyyy(".") - - def _get_ddmmyyyy(self,sep): - retval = "" - - if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF : - pass - elif self.day == UNDEF: - if self.month == UNDEF: - retval = str(self.year) - elif self.year == UNDEF: - retval = "??%s%02d%s??" % (sep,self.month+1,sep) - else: - retval = "??%s%02d%s%04d" % (sep,self.month+1,sep,self.year) - elif self.month == UNDEF: - retval = "%02d%s??%s%04d" % (self.day,sep,sep,self.year) - else: - if self.year == UNDEF: - retval = "%02d%s%02d%s????" % (self.day,sep,self.month+1,sep) - else: - retval = "%02d%s%02d%s%04d" % (self.day,sep,self.month+1,sep,self.year) - - if self.mode == Calendar.ABOUT: - retval = "%s %s" % (_("ABOUT"),retval) - if self.mode == Calendar.BEFORE: - retval = "%s %s" % (_("BEFORE"),retval) - elif self.mode == Calendar.AFTER: - retval = "%s %s" % (_("AFTER"),retval) - - return retval - - def _format6(self): - return self._get_ddmmyyyy("/") - - def _format7(self): - return self._get_ddmmyyyy("-") - - def _format9(self): - return self._get_ddmmyyyy(".") - - def _format11(self): - return self._get_yyyymmdd("/") - - def _format12(self): - return self._get_yyyymmdd("-") - - def _format13(self): - return self._get_yyyymmdd(".") - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - fmtFunc = [ _format1, _format2, _format3, _format4, _format5, _format6, - _format7, _format8, _format9, _format10, _format11, _format12, - _format13] def getDate(self): return self.calendar.display(self.year, self.month, self.day, self.mode) @@ -691,8 +431,6 @@ def compare_dates(f,s): else: return cmp(first.day,second.day) -_func = SingleDate.fmtFunc[0] - if __name__ == "__main__": diff --git a/src/GrampsCfg.py b/src/GrampsCfg.py index 8fdc7b51b..34c245c79 100644 --- a/src/GrampsCfg.py +++ b/src/GrampsCfg.py @@ -29,6 +29,7 @@ import os import PaperMenu import Plugins +import Calendar #------------------------------------------------------------------------- # @@ -283,8 +284,8 @@ def loadConfig(call): autocomp = not ac - set_format_code(dateFormat) - Date.entryCode = dateEntry + Calendar.set_format_code(dateFormat) + Calendar.ENTRYCODE = dateEntry if _name_format == 0: nameof = Utils.normal_name @@ -659,7 +660,7 @@ class GrampsPreferences: item.connect("activate", self.on_format_toggled) item.show() date_menu.append(item) - date_menu.set_active(get_format_code()) + date_menu.set_active(Calendar.get_format_code()) date_option.set_menu(date_menu) date_entry = self.top.get_widget("date_entry_format") @@ -670,7 +671,7 @@ class GrampsPreferences: item.connect("activate", self.on_format_toggled) item.show() date_menu.append(item) - date_menu.set_active(Date.entryCode) + date_menu.set_active(Calendar.ENTRYCODE) date_entry.set_menu(date_menu) name_option = self.top.get_widget("name_format") @@ -905,13 +906,13 @@ class GrampsPreferences: format_menu = self.top.get_widget("date_format").get_menu() active = format_menu.get_active().get_data(INDEX) - set_format_code(active) + Calendar.set_format_code(active) set_int("/apps/gramps/date-format",active) format_menu = self.top.get_widget("date_entry_format").get_menu() entry_active = format_menu.get_active().get_data(INDEX) - Date.entryCode = entry_active + Calendar.ENTRYCODE = entry_active set_int("/apps/gramps/date-entry",entry_active) # get the name format