3756: Cannot set new year value different than default (first January)

svn: r15010
This commit is contained in:
Doug Blank 2010-04-03 23:33:17 +00:00
parent 0e330eb929
commit 7047015603
5 changed files with 84 additions and 52 deletions

View File

@ -186,7 +186,6 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
"""
Initiate and display the dialog.
"""
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
# Create self.date as a copy of the given Date object.
@ -240,7 +239,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
self.dual_dated = self.top.get_object('dualdated')
self.new_year = self.top.get_object('newyear')
self.new_year.set_active(self.date.get_new_year())
self.new_year.set_text(self.date.newyear_to_str())
# Disable second date controls if not compound date
if not self.date.is_compound():
@ -341,7 +340,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
self.start_year.get_value_as_int(),
self.dual_dated.get_active())
calendar = self.calendar_box.get_active()
newyear = self.new_year.get_active()
newyear = self.date.newyear_to_code(self.new_year.get_text())
return (quality, modifier, calendar, value, text, newyear)
def switch_type(self, obj):

View File

@ -139,12 +139,17 @@ class DateDisplay(object):
Formats the extra items (calendar, newyear) for a date.
"""
scal = self.calendar[cal]
snewyear = self.newyear[newyear]
if isinstance(newyear, int) and newyear <= len(self.newyear):
snewyear = self.newyear[newyear]
elif isinstance(newyear, (list, tuple)):
snewyear = "%s-%s" % (newyear[0], newyear[1])
else:
snewyear = "Err"
retval = ""
for item in [scal, snewyear]:
if item:
if retval:
retval += ","
retval += ", "
retval += item
if retval:
return " (%s)" % retval

View File

@ -317,20 +317,25 @@ class DateParser(object):
self._imon_str = self.re_longest_first(self.islamic_to_int.keys())
self._smon_str = self.re_longest_first(self.swedish_to_int.keys())
self._cal_str = self.re_longest_first(self.calendar_to_int.keys())
self._ny_str = self.re_longest_first(self.newyear_to_int.keys())
self._ny_str = self.re_longest_first(self.newyear_to_int.keys())
# bce, calendar type and quality may be either at the end or at
# the beginning of the given date string, therefore they will
# be parsed from the middle and will be in match.group(2).
self._bce_re = re.compile("(.*)\s+%s( ?.*)" % self._bce_str)
self._bce_re = re.compile("(.*)\s+%s( ?.*)" % self._bce_str)
self._cal = re.compile("(.*)\s+\(%s\)( ?.*)" % self._cal_str,
re.IGNORECASE)
self._calny = re.compile("(.*)\s+\(%s,\s*%s\)( ?.*)" % (self._cal_str,
self._ny_str),
re.IGNORECASE)
self._calny_iso = re.compile("(.*)\s+\(%s,\s*(\d{1,2}-\d{1,2})\)( ?.*)" % self._cal_str,
re.IGNORECASE)
self._ny = re.compile("(.*)\s+\(%s\)( ?.*)" % self._ny_str,
re.IGNORECASE)
self._ny_iso = re.compile("(.*)\s+\((\d{1,2}-\d{1,2})\)( ?.*)")
self._cal = re.compile("(.*)\s+\(%s\)( ?.*)" % self._cal_str,
re.IGNORECASE)
self._calny = re.compile("(.*)\s+\(%s,%s\)( ?.*)" % (self._cal_str,
self._ny_str),
re.IGNORECASE)
self._ny = re.compile("(.*)\s+\(%s\)( ?.*)" % self._ny_str,
re.IGNORECASE)
self._qual = re.compile("(.* ?)%s\s+(.+)" % self._qual_str,
re.IGNORECASE)
@ -562,6 +567,12 @@ class DateParser(object):
cal = self.calendar_to_int[match.group(2).lower()]
newyear = self.newyear_to_int[match.group(3).lower()]
text = match.group(1) + match.group(4)
else:
match = self._calny_iso.match(text)
if match:
cal = self.calendar_to_int[match.group(2).lower()]
newyear = tuple([int(s) for s in match.group(3).split("-")])
text = match.group(1) + match.group(4)
return (text, cal, newyear)
def match_newyear(self, text, newyear):
@ -574,6 +585,11 @@ class DateParser(object):
if match:
newyear = self.newyear_to_int[match.group(2).lower()]
text = match.group(1) + match.group(3)
else:
match = self._ny_iso.match(text)
if match:
newyear = tuple([int(s) for s in match.group(2).split("-")])
text = match.group(1) + match.group(3)
return (text, newyear)
def match_quality(self, text, qual):

View File

@ -1012,16 +1012,7 @@ class Date(object):
else:
pref = ""
if self.newyear == Date.NEWYEAR_JAN1:
ny = ""
elif self.newyear == Date.NEWYEAR_MAR1:
ny = "Mar1"
elif self.newyear == Date.NEWYEAR_MAR25:
ny = "Mar25"
elif self.newyear == Date.NEWYEAR_SEP1:
ny = "Sep1"
else:
ny = "Err"
ny = self.newyear_str()
if self.calendar != Date.CAL_GREGORIAN:
if ny:
@ -1053,6 +1044,46 @@ class Date(object):
self.dateval[Date._POS_DAY])
return "%s%s%s%s" % (qual, pref, val, cal)
def newyear_to_str(self):
"""
Return the string representation of the newyear.
"""
if self.newyear == Date.NEWYEAR_JAN1:
ny = ""
elif self.newyear == Date.NEWYEAR_MAR1:
ny = "Mar1"
elif self.newyear == Date.NEWYEAR_MAR25:
ny = "Mar25"
elif self.newyear == Date.NEWYEAR_SEP1:
ny = "Sep1"
elif isinstance(self.newyear, (list, tuple)):
ny = "%s-%s" % (self.newyear[0], self.newyear[1])
else:
ny = "Err"
return ny
def newyear_to_code(self, string):
"""
Return the code of a newyear string.
"""
string = string.strip().lower()
if string == "" or string == "jan1":
code = Date.NEWYEAR_JAN1
elif string == "mar1":
code = Date.NEWYEAR_MAR1
elif self.newyear == "mar25":
code = Date.NEWYEAR_MAR25
elif self.newyear == "sep1":
code = Date.NEWYEAR_SEP1
elif "-" in string:
try:
code = tuple([int(n) for n in string.split("-")])
except:
code = 0
else:
code = 0
return code
def get_sort_value(self):
"""
Return the sort value of Date object.
@ -1429,6 +1460,8 @@ class Date(object):
(DD, MM, YY, slash1, DD, MM, YY, slash2)
text - A text string holding either the verbatim user input
or a comment relating to the date.
newyear - The newyear code, or tuple representing (month, day)
of newyear day.
The sort value is recalculated.
"""
@ -1479,6 +1512,10 @@ class Date(object):
split = (3, 25)
elif ny == Date.NEWYEAR_SEP1:
split = (9, 1)
elif isinstance(ny, (list, tuple)):
split = ny
else:
split = (0, 0)
if (self.get_month(), self.get_day()) >= split:
d1 = Date(self.get_year(), 1, 1)
d1.set_calendar(self.calendar)

View File

@ -119,16 +119,11 @@
</packing>
</child>
<child>
<object class="GtkComboBox" id="newyear">
<object class="GtkEntry" id="newyear">
<property name="visible">True</property>
<property name="model">newyear_model</property>
<property name="tooltip_text"
translatable="yes">Month-Day of first day of new year (e.g., "Jan1", "Mar1", "3-1", "3-25")</property>
<accelerator key="w" signal="grab_focus" modifiers="GDK_MOD1_MASK"/>
<child>
<object class="GtkCellRendererText" id="renderer1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="position">3</property>
@ -599,26 +594,6 @@
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="newyear_model">
<columns>
<!-- column-name gchararray2 -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">January 1</col>
</row>
<row>
<col id="0" translatable="yes">March 1</col>
</row>
<row>
<col id="0" translatable="yes">March 25</col>
</row>
<row>
<col id="0" translatable="yes">September 1</col>
</row>
</data>
</object>
<object class="GtkListStore" id="quality_model">
<columns>
<!-- column-name gchararray3 -->