Package DateHandler :: Module _DateUtils
[frames] | no frames]

Source Code for Module DateHandler._DateUtils

 1  # 
 2  # Gramps - a GTK+/GNOME based genealogy program 
 3  # 
 4  # Copyright (C) 2004-2006  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  # $Id: _DateUtils.py 10094 2008-02-22 10:50:06Z acraphae $ 
22   
23  """ 
24  Class handling language-specific selection for date parser and displayer. 
25  """ 
26   
27  #------------------------------------------------------------------------- 
28  # 
29  # GRAMPS modules 
30  # 
31  #------------------------------------------------------------------------- 
32  from DateHandler import LANG_TO_DISPLAY, LANG, parser, displayer 
33   
34  #-------------------------------------------------------------- 
35  # 
36  # Convenience functions 
37  # 
38  #-------------------------------------------------------------- 
39 -def get_date_formats():
40 """ 41 Return the lists supported formats for date parsers and displayers. 42 """ 43 try: 44 return LANG_TO_DISPLAY[LANG].formats 45 except: 46 return LANG_TO_DISPLAY["C"].formats
47
48 -def set_format(value):
49 try: 50 displayer.set_format(value) 51 except: 52 pass
53
54 -def set_date(date_base, text) :
55 """ 56 Set the date of the DateBase instance. 57 58 The date is parsed into a Date instance. 59 60 @param date_base: The DateBase instance to set the date to. 61 @type date_base: DateBase 62 @param text: The text to use for the text string in date 63 @type text: str 64 65 """ 66 parser.set_date(date_base.get_date_object(), text)
67
68 -def get_date(date_base) :
69 """ 70 Return a string representation of the date of the DateBase instance. 71 72 This representation is based off the default date display format 73 determined by the locale's DateDisplay instance. 74 @return: Returns a string representing the DateBase date 75 @rtype: str 76 77 """ 78 return displayer.display(date_base.get_date_object())
79
80 -def get_quote_date(date_base):
81 """ 82 Return a string representation of the date of the DateBase instance. 83 84 This representation is based off the default date display format 85 determined by the locale's DateDisplay instance. The date is 86 enclosed in quotes if the Date is not a valid date. 87 88 @return: Returns a string representing the DateBase date 89 @rtype: str 90 91 """ 92 return displayer.quote_display(date_base.get_date_object())
93