2001-06-04 07:13:11 +05:30
|
|
|
#
|
2001-05-13 07:26:57 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000 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
|
|
|
|
#
|
|
|
|
|
|
|
|
"Support for the dates"
|
|
|
|
|
|
|
|
import re
|
|
|
|
import string
|
|
|
|
import intl
|
|
|
|
|
|
|
|
_ = intl.gettext
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class Date:
|
|
|
|
formatCode = 0
|
2001-05-17 18:55:28 +05:30
|
|
|
entryCode = 0
|
|
|
|
|
2001-06-22 09:01:09 +05:30
|
|
|
Error = "Illegal Date"
|
2001-05-16 04:24:04 +05:30
|
|
|
|
|
|
|
range = 1
|
|
|
|
normal = 0
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2001-06-04 07:13:11 +05:30
|
|
|
from_str = _("(from|between|bet|bet.)")
|
2001-06-04 04:48:07 +05:30
|
|
|
to_str = _("(and|to|-)")
|
2001-05-14 01:12:15 +05:30
|
|
|
|
2001-06-04 07:13:11 +05:30
|
|
|
efmt = re.compile(r"\s*(from|between|bet)\s+(.+)\s+(and|to)\s+(.+)\s*$",
|
2001-05-13 07:26:57 +05:30
|
|
|
re.IGNORECASE)
|
|
|
|
|
2001-06-04 07:13:11 +05:30
|
|
|
fmt = re.compile(r"\s*" + from_str + r"\s+(.+)\s+" + to_str + r"\s+(.+)\s*$",
|
2001-05-17 08:29:15 +05:30
|
|
|
re.IGNORECASE)
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def __init__(self):
|
|
|
|
self.start = SingleDate()
|
2001-06-20 02:18:35 +05:30
|
|
|
self.stop = None
|
2001-05-13 07:26:57 +05:30
|
|
|
self.range = 0
|
2001-05-16 04:24:04 +05:30
|
|
|
self.text = ""
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
def get_start_date(self):
|
|
|
|
return self.start
|
|
|
|
|
|
|
|
def get_stop_date(self):
|
2001-06-20 02:18:35 +05:30
|
|
|
if self.stop == None:
|
|
|
|
self.stop = SingleDate()
|
2001-05-13 07:26:57 +05:30
|
|
|
return self.stop
|
|
|
|
|
2001-05-30 09:54:27 +05:30
|
|
|
def getYear(self):
|
|
|
|
return self.get_start_date().getYear()
|
|
|
|
|
|
|
|
def getMonth(self):
|
|
|
|
return self.get_start_date().getMonth()
|
|
|
|
|
|
|
|
def getDay(self):
|
|
|
|
return self.get_start_date().getDay()
|
|
|
|
|
|
|
|
def getStopYear(self):
|
2001-06-20 02:18:35 +05:30
|
|
|
if self.stop == None:
|
|
|
|
self.stop = SingleDate()
|
2001-05-30 09:54:27 +05:30
|
|
|
return self.get_stop_date().getYear()
|
|
|
|
|
|
|
|
def getStopMonth(self):
|
2001-06-20 02:18:35 +05:30
|
|
|
if self.stop == None:
|
|
|
|
self.stop = SingleDate()
|
2001-05-30 09:54:27 +05:30
|
|
|
return self.get_stop_date().getMonth()
|
|
|
|
|
|
|
|
def getStopDay(self):
|
2001-06-20 02:18:35 +05:30
|
|
|
if self.stop == None:
|
|
|
|
self.stop = SingleDate()
|
2001-05-30 09:54:27 +05:30
|
|
|
return self.get_stop_date().getDay()
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def set(self,text):
|
|
|
|
match = Date.fmt.match(text)
|
2001-05-16 04:24:04 +05:30
|
|
|
try:
|
|
|
|
if match:
|
|
|
|
matches = match.groups()
|
|
|
|
self.start.set(matches[1])
|
2001-06-20 02:18:35 +05:30
|
|
|
if self.stop == None:
|
|
|
|
self.stop = SingleDate()
|
2001-05-16 04:24:04 +05:30
|
|
|
self.stop.set(matches[3])
|
|
|
|
self.range = 1
|
|
|
|
else:
|
|
|
|
self.start.set(text)
|
|
|
|
self.range = 0
|
|
|
|
except:
|
|
|
|
self.range = -1
|
|
|
|
self.text = text
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getDate(self):
|
2001-06-17 19:10:57 +05:30
|
|
|
if self.range == 0:
|
|
|
|
return _func(self.start)
|
2001-05-16 04:24:04 +05:30
|
|
|
elif self.range == -1:
|
|
|
|
return self.text
|
|
|
|
else:
|
2001-06-23 22:28:23 +05:30
|
|
|
return "%s %s %s %s" % ( _("from"),_func(self.start),_("to"), _func(self.stop))
|
2001-05-16 04:24:04 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getQuoteDate(self):
|
2001-06-17 19:10:57 +05:30
|
|
|
if self.range == 0:
|
|
|
|
return _func(self.start)
|
2001-06-23 22:28:23 +05:30
|
|
|
elif self.range == -1:
|
|
|
|
if self.text:
|
|
|
|
return '"%s"' % self.text
|
|
|
|
else:
|
|
|
|
return ''
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-06-23 22:28:23 +05:30
|
|
|
return "%s %s %s %s" % ( _("from"),_func(self.start),_("to"), _func(self.stop))
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getSaveDate(self):
|
2001-05-16 04:24:04 +05:30
|
|
|
if self.range == 1:
|
2001-05-26 20:51:22 +05:30
|
|
|
return "FROM " + self.start.getSaveDate() + " TO " + self.stop.getSaveDate()
|
2001-05-16 04:24:04 +05:30
|
|
|
elif self.range == -1:
|
|
|
|
return self.text
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-05-26 20:51:22 +05:30
|
|
|
return self.start.getSaveDate()
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2001-05-18 04:41:23 +05:30
|
|
|
def isEmpty(self):
|
|
|
|
if self.start.year == -1 and self.start.month == -1 and self.start.day == -1:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def isValid(self):
|
|
|
|
if self.range == -1:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return 1
|
2001-05-20 00:11:47 +05:30
|
|
|
|
|
|
|
def isRange(self):
|
|
|
|
if self.range == -1:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return 1
|
2001-05-18 04:41:23 +05:30
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def quick_set(self,text):
|
2001-05-16 04:24:04 +05:30
|
|
|
try:
|
2001-05-17 08:29:15 +05:30
|
|
|
match = Date.efmt.match(text)
|
|
|
|
if match:
|
|
|
|
matches = match.groups()
|
|
|
|
self.start.set(matches[1])
|
2001-06-20 02:18:35 +05:30
|
|
|
if self.stop == None:
|
|
|
|
self.stop = SingleDate()
|
2001-05-17 08:29:15 +05:30
|
|
|
self.stop.set(matches[3])
|
|
|
|
self.range = 1
|
2001-05-16 04:24:04 +05:30
|
|
|
else:
|
|
|
|
try:
|
|
|
|
self.start.quick_set(text)
|
|
|
|
self.range = 0
|
|
|
|
except:
|
|
|
|
self.start.set(text)
|
|
|
|
self.range = 0
|
|
|
|
except:
|
|
|
|
self.range = -1
|
|
|
|
self.text = text
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2001-06-17 19:10:57 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def set_format_code(code):
|
|
|
|
global _func
|
|
|
|
Date.formatCode = code
|
|
|
|
_func = SingleDate.fmtFunc[code]
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def get_format_code():
|
|
|
|
return Date.formatCode
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class SingleDate:
|
|
|
|
"Date handling"
|
|
|
|
|
|
|
|
exact = 0
|
|
|
|
about = 1
|
|
|
|
before = 2
|
|
|
|
after = 3
|
|
|
|
|
2001-05-17 07:31:02 +05:30
|
|
|
mname = [ _("January"),
|
|
|
|
_("February"),
|
|
|
|
_("March"),
|
|
|
|
_("April"),
|
|
|
|
_("May"),
|
|
|
|
_("June"),
|
|
|
|
_("July"),
|
|
|
|
_("August"),
|
|
|
|
_("September"),
|
|
|
|
_("October"),
|
|
|
|
_("November"),
|
|
|
|
_("December") ]
|
|
|
|
|
2001-05-17 08:13:10 +05:30
|
|
|
emname =[ 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
|
|
|
|
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC' ]
|
|
|
|
|
2001-05-17 07:31:02 +05:30
|
|
|
m2num = { string.lower(mname[0][0:3]) : 0,
|
|
|
|
string.lower(mname[1][0:3]) : 1,
|
|
|
|
string.lower(mname[2][0:3]) : 2,
|
|
|
|
string.lower(mname[3][0:3]) : 3,
|
|
|
|
string.lower(mname[4][0:3]) : 4,
|
|
|
|
string.lower(mname[5][0:3]) : 5,
|
|
|
|
string.lower(mname[6][0:3]) : 6,
|
|
|
|
string.lower(mname[7][0:3]) : 7,
|
|
|
|
string.lower(mname[8][0:3]) : 8,
|
|
|
|
string.lower(mname[9][0:3]) : 9,
|
|
|
|
string.lower(mname[10][0:3]) : 10,
|
|
|
|
string.lower(mname[11][0:3]) : 11 }
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2001-06-20 02:18:35 +05:30
|
|
|
em2num ={ "jan" : 0, "feb" : 1, "mar" : 2, "apr" : 3,
|
|
|
|
"may" : 4, "jun" : 5, "jul" : 6, "aug" : 7,
|
|
|
|
"sep" : 8, "oct" : 9, "nov" : 10,"dec" : 11 }
|
2001-05-17 08:13:10 +05:30
|
|
|
|
2001-05-14 01:12:15 +05:30
|
|
|
m2v = { _("abt") : about ,
|
|
|
|
_("about") : about,
|
2001-06-04 07:13:11 +05:30
|
|
|
_("abt.") : about,
|
2001-05-14 01:12:15 +05:30
|
|
|
_("est") : about ,
|
2001-06-04 07:13:11 +05:30
|
|
|
_("est.") : about ,
|
2001-05-14 01:12:15 +05:30
|
|
|
_("circa") : about,
|
|
|
|
_("around") : about,
|
|
|
|
_("before") : before,
|
|
|
|
_("bef") : before,
|
2001-06-04 07:13:11 +05:30
|
|
|
_("bef.") : before,
|
2001-05-14 01:12:15 +05:30
|
|
|
_("after") : after,
|
2001-06-04 07:13:11 +05:30
|
|
|
_("aft.") : after,
|
2001-05-14 01:12:15 +05:30
|
|
|
_("aft") : after }
|
|
|
|
|
|
|
|
modifiers = "(" + \
|
|
|
|
_("abt") + '|' + \
|
2001-06-04 07:13:11 +05:30
|
|
|
_("abt\.") + '|' + \
|
2001-05-14 01:12:15 +05:30
|
|
|
_("about") + '|' + \
|
|
|
|
_("est") + '|' + \
|
2001-06-04 07:13:11 +05:30
|
|
|
_("est\.") + '|' + \
|
2001-05-14 01:12:15 +05:30
|
|
|
_("circa") + '|' + \
|
|
|
|
_("around") + '|' + \
|
|
|
|
_("before") + '|' + \
|
|
|
|
_("after") + '|' + \
|
|
|
|
_("aft") + '|' + \
|
2001-06-04 07:13:11 +05:30
|
|
|
_("aft\.") + '|' + \
|
|
|
|
_("bef\.") + '|' + \
|
2001-05-23 04:00:13 +05:30
|
|
|
_("bef") + ')'
|
2001-05-14 01:12:15 +05:30
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
start = "^\s*" + modifiers + "?\s*"
|
|
|
|
|
|
|
|
fmt1 = re.compile(start + "(\S+)(\s+\d+\s*,)?\s*(\d+)?\s*$",
|
|
|
|
re.IGNORECASE)
|
2001-07-01 04:31:38 +05:30
|
|
|
fmt2 = re.compile(start + "(\d+)\.?\s+(\S+)(\s+\d+)?\s*$",
|
2001-05-13 07:26:57 +05:30
|
|
|
re.IGNORECASE)
|
2001-05-16 04:24:04 +05:30
|
|
|
quick= re.compile(start + "(\d+)?\s(\S\S\S)?\s(\d+)?",
|
2001-05-13 07:26:57 +05:30
|
|
|
re.IGNORECASE)
|
2001-05-26 19:08:00 +05:30
|
|
|
fmt3 = re.compile(start + r"([?\d]+)\s*[./-]\s*([?\d]+)\s*[./-]\s*([?\d]+)\s*$",
|
|
|
|
re.IGNORECASE)
|
|
|
|
fmt7 = re.compile(start + r"([?\d]+)\s*[./-]\s*([?\d]+)\s*$",
|
2001-05-13 07:26:57 +05:30
|
|
|
re.IGNORECASE)
|
|
|
|
fmt4 = re.compile(start + "(\S+)\s+(\d+)\s*$",
|
|
|
|
re.IGNORECASE)
|
|
|
|
fmt5 = re.compile(start + "(\d+)\s*$",
|
|
|
|
re.IGNORECASE)
|
|
|
|
fmt6 = re.compile(start + "(\S+)\s*$",
|
|
|
|
re.IGNORECASE)
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
self.month = -1
|
|
|
|
self.day = -1
|
|
|
|
self.year = -1
|
|
|
|
self.mode = SingleDate.exact
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def __cmp__(self,other):
|
2001-07-08 11:14:42 +05:30
|
|
|
if other == None:
|
|
|
|
return 0
|
|
|
|
elif self.year != other.year:
|
2001-05-13 07:26:57 +05:30
|
|
|
return cmp(self.year,other.year)
|
|
|
|
elif self.month != other.month:
|
|
|
|
return cmp(self.month,other.month)
|
|
|
|
elif self.day != other.day:
|
|
|
|
return cmp(self.day,other.day)
|
|
|
|
elif self.mode != other.mode:
|
|
|
|
if self.mode == SingleDate.exact:
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def setMode(self,val):
|
|
|
|
if val == None:
|
|
|
|
self.mode = SingleDate.exact
|
|
|
|
else:
|
|
|
|
val = string.lower(val)
|
|
|
|
self.mode = SingleDate.m2v[val]
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def setMonth(self,val):
|
2001-06-22 05:25:59 +05:30
|
|
|
if val > 12:
|
|
|
|
self.month = -1
|
|
|
|
else:
|
|
|
|
self.month = val - 1
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getMonth(self):
|
|
|
|
return self.month + 1
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def setDay(self,val):
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = val
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getDay(self):
|
|
|
|
return self.day
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def setYear(self,val):
|
|
|
|
self.year = val
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getYear(self):
|
|
|
|
return self.year
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def setMonthStr(self,text):
|
2001-06-17 19:10:57 +05:30
|
|
|
try:
|
2001-05-13 07:26:57 +05:30
|
|
|
self.month = SingleDate.m2num[string.lower(text[0:3])]
|
2001-06-26 19:49:35 +05:30
|
|
|
except KeyError:
|
2001-05-13 07:26:57 +05:30
|
|
|
self.month = -1
|
|
|
|
|
2001-05-14 01:12:15 +05:30
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def setMonthStrEng(self,text):
|
2001-06-17 19:10:57 +05:30
|
|
|
try:
|
2001-05-17 08:13:10 +05:30
|
|
|
self.month = SingleDate.em2num[string.lower(text[0:3])]
|
2001-06-26 19:49:35 +05:30
|
|
|
except KeyError:
|
2001-05-14 01:12:15 +05:30
|
|
|
self.month = -1
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getMonthStr(self):
|
|
|
|
return SingleDate.mname[self.month]
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getSaveDate(self):
|
2001-05-17 08:13:10 +05:30
|
|
|
retval = ""
|
|
|
|
|
|
|
|
if self.month == -1 and self.day == -1 and self.year == -1 :
|
|
|
|
pass
|
|
|
|
elif self.day == -1:
|
|
|
|
if self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-17 08:13:10 +05:30
|
|
|
elif self.year == -1:
|
|
|
|
retval = SingleDate.emname[self.month]
|
|
|
|
else:
|
|
|
|
retval = "%s %d" % (SingleDate.emname[self.month],self.year)
|
|
|
|
elif self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-17 08:13:10 +05:30
|
|
|
else:
|
|
|
|
month = SingleDate.emname[self.month]
|
|
|
|
if self.year == -1:
|
|
|
|
retval = "%d %s ????" % (self.day,month)
|
|
|
|
else:
|
|
|
|
retval = "%d %s %d" % (self.day,month,self.year)
|
|
|
|
|
|
|
|
if self.mode == SingleDate.about:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "ABT %s" % retval
|
2001-05-17 08:13:10 +05:30
|
|
|
|
|
|
|
if self.mode == SingleDate.before:
|
|
|
|
retval = _("BEFORE") + " " + retval
|
|
|
|
elif self.mode == SingleDate.after:
|
|
|
|
retval = _("AFTER") + " " + retval
|
|
|
|
|
|
|
|
return retval
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getFmt1(self):
|
|
|
|
|
|
|
|
if self.month == -1 and self.day == -1 and self.year == -1 :
|
2001-06-17 19:10:57 +05:30
|
|
|
return ""
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.day == -1:
|
|
|
|
if self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.year == -1:
|
|
|
|
retval = SingleDate.mname[self.month]
|
|
|
|
else:
|
|
|
|
retval = "%s %d" % (SingleDate.mname[self.month],self.year)
|
|
|
|
elif self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
else:
|
2001-05-13 07:26:57 +05:30
|
|
|
month = SingleDate.mname[self.month]
|
|
|
|
if self.year == -1:
|
|
|
|
retval = "%s %d, ????" % (month,self.day)
|
|
|
|
else:
|
|
|
|
retval = "%s %d, %d" % (month,self.day,self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
|
|
|
if self.mode == SingleDate.about:
|
|
|
|
retval = _("about") + ' ' + retval
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
if self.mode == SingleDate.before:
|
2001-05-17 04:51:18 +05:30
|
|
|
retval = _("before") + ' ' + retval
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.mode == SingleDate.after:
|
2001-05-17 04:51:18 +05:30
|
|
|
retval = _("after") + ' ' + retval
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getFmt2(self):
|
|
|
|
if self.month == -1 and self.day == -1 and self.year == -1 :
|
2001-06-17 19:10:57 +05:30
|
|
|
return ""
|
|
|
|
elif self.month != -1 and self.month != -1:
|
|
|
|
month = SingleDate.mname[self.month]
|
|
|
|
if self.year == -1:
|
|
|
|
retval = "%s %d, ????" % (string.upper(month[0:3]),self.day)
|
|
|
|
else:
|
|
|
|
retval = "%s %d, %d" % (string.upper(month[0:3]),self.day,self.year)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.day == -1:
|
|
|
|
if self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.year == -1:
|
|
|
|
month = SingleDate.mname[self.month]
|
|
|
|
retval = string.upper(month[0:3])
|
|
|
|
else:
|
|
|
|
month = SingleDate.mname[self.month]
|
|
|
|
retval = "%s %d" % (string.upper(month[0:3]),self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
2001-06-17 19:10:57 +05:30
|
|
|
if self.mode == SingleDate.about:
|
2001-06-20 02:18:35 +05:30
|
|
|
retval = "%s %s" % (_("abt"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
if self.mode == SingleDate.before:
|
2001-06-20 02:18:35 +05:30
|
|
|
retval = "%s %s" % (_("before"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.mode == SingleDate.after:
|
2001-06-20 02:18:35 +05:30
|
|
|
retval = "%s %s" % (_("after"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getFmt3(self):
|
|
|
|
retval = ""
|
|
|
|
|
|
|
|
if self.month == -1 and self.day == -1 and self.year == -1 :
|
|
|
|
pass
|
|
|
|
elif self.day == -1:
|
|
|
|
if self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.year == -1:
|
|
|
|
month = SingleDate.mname[self.month]
|
|
|
|
retval = string.upper(month[0:3])
|
2001-06-22 05:25:59 +05:30
|
|
|
else:
|
2001-05-13 07:26:57 +05:30
|
|
|
month = SingleDate.mname[self.month]
|
|
|
|
retval = "%s %d" % (string.upper(month[0:3]),self.year)
|
|
|
|
elif self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
|
|
|
month = SingleDate.mname[self.month]
|
|
|
|
if self.year == -1:
|
|
|
|
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 == SingleDate.about:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("ABT"),retval)
|
2001-05-17 04:51:18 +05:30
|
|
|
if self.mode == SingleDate.before:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("BEFORE"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.mode == SingleDate.after:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("AFTER"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
2001-07-01 04:31:38 +05:30
|
|
|
def getFmt10(self):
|
2001-05-13 07:26:57 +05:30
|
|
|
retval = ""
|
|
|
|
|
|
|
|
if self.month == -1 and self.day == -1 and self.year == -1 :
|
|
|
|
pass
|
|
|
|
elif self.day == -1:
|
|
|
|
if self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-17 18:55:28 +05:30
|
|
|
elif self.year == -1:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = SingleDate.mname[self.month]
|
2001-05-17 18:55:28 +05:30
|
|
|
else:
|
2001-07-01 04:31:38 +05:30
|
|
|
month = SingleDate.mname[self.month]
|
|
|
|
retval = "%s %d" % (month,self.year)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.month == -1:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = str(self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
else:
|
2001-07-01 04:31:38 +05:30
|
|
|
month = SingleDate.mname[self.month]
|
2001-05-17 18:55:28 +05:30
|
|
|
if self.year == -1:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "%d. %s ????" % (self.day,month)
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "%d. %s %d" % (self.day,month,self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
|
|
|
if self.mode == SingleDate.about:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("ABT"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
if self.mode == SingleDate.before:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("BEFORE"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.mode == SingleDate.after:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("AFTER"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
2001-07-01 04:31:38 +05:30
|
|
|
def get_mmddyyyy(self,sep):
|
2001-05-13 07:26:57 +05:30
|
|
|
retval = ""
|
|
|
|
|
|
|
|
if self.month == -1 and self.day == -1 and self.year == -1 :
|
|
|
|
pass
|
|
|
|
elif self.day == -1:
|
|
|
|
if self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-17 18:55:28 +05:30
|
|
|
elif self.year == -1:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "%d%s??%s??" % (self.month+1,sep,sep)
|
2001-05-17 18:55:28 +05:30
|
|
|
else:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "%d%s??%s%d" % (self.month+1,sep,sep,self.year)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.month == -1:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "??%s%d%s%d" % (sep,self.day,sep,self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
else:
|
2001-05-13 07:26:57 +05:30
|
|
|
if self.year == -1:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "%d%s%d%s????" % (self.month+1,sep,self.day,sep)
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "%d%s%d%s%d" % (self.month+1,sep,self.day,sep,self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
|
|
|
if self.mode == SingleDate.about:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("ABT"),retval)
|
2001-07-01 04:31:38 +05:30
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
if self.mode == SingleDate.before:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("BEFORE"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.mode == SingleDate.after:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("AFTER"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
2001-07-01 04:31:38 +05:30
|
|
|
def getFmt4(self):
|
|
|
|
return self.get_mmddyyyy("/")
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getFmt5(self):
|
|
|
|
return self.get_mmddyyyy("-")
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getFmt8(self):
|
|
|
|
return self.get_mmddyyyy(".")
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def get_ddmmyyyy(self,sep):
|
2001-05-13 07:26:57 +05:30
|
|
|
retval = ""
|
|
|
|
|
|
|
|
if self.month == -1 and self.day == -1 and self.year == -1 :
|
|
|
|
pass
|
|
|
|
elif self.day == -1:
|
|
|
|
if self.month == -1:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = str(self.year)
|
2001-05-17 18:55:28 +05:30
|
|
|
elif self.year == -1:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "??%s%d%s??" % (sep,self.month+1,sep)
|
2001-05-17 18:55:28 +05:30
|
|
|
else:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "??%s%d%s%d" % (sep,self.month+1,sep,self.year)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.month == -1:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "%d%s??%s%d" % (self.day,sep,sep,self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
else:
|
2001-05-13 07:26:57 +05:30
|
|
|
if self.year == -1:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "%d%s%d%s????" % (self.day,sep,self.month+1,sep)
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-07-01 04:31:38 +05:30
|
|
|
retval = "%d%s%d%s%d" % (self.day,sep,self.month+1,sep,self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
|
|
|
if self.mode == SingleDate.about:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("ABT"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
if self.mode == SingleDate.before:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("BEFORE"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
elif self.mode == SingleDate.after:
|
2001-06-17 19:10:57 +05:30
|
|
|
retval = "%s %s" % (_("AFTER"),retval)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
return retval
|
2001-07-01 04:31:38 +05:30
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getFmt6(self):
|
|
|
|
return self.get_ddmmyyyy("/")
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getFmt7(self):
|
2001-07-01 04:31:38 +05:30
|
|
|
return self.get_ddmmyyyy("-")
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2001-07-01 04:31:38 +05:30
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getFmt9(self):
|
|
|
|
return self.get_ddmmyyyy(".")
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
2001-07-01 04:31:38 +05:30
|
|
|
fmtFunc = [ getFmt1, getFmt2, getFmt3, getFmt4, getFmt5, getFmt6,
|
|
|
|
getFmt7, getFmt8, getFmt9, getFmt10 ]
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getDate(self):
|
|
|
|
function = SingleDate.fmtFunc[Date.formatCode]
|
|
|
|
return function(self)
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def getMode(self,val):
|
|
|
|
if val == None:
|
|
|
|
self.mode = SingleDate.exact
|
|
|
|
elif string.lower(val)[0:3] == "bef":
|
|
|
|
self.mode = SingleDate.before
|
|
|
|
elif string.lower(val)[0:3] == "aft":
|
|
|
|
self.mode = SingleDate.after
|
|
|
|
else:
|
|
|
|
self.mode = SingleDate.about
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def set(self,text):
|
|
|
|
match = SingleDate.fmt2.match(text)
|
|
|
|
if match != None:
|
|
|
|
matches = match.groups()
|
|
|
|
self.getMode(matches[0])
|
|
|
|
self.setMonthStr(matches[2])
|
2001-06-26 19:49:35 +05:30
|
|
|
if self.month == -1:
|
|
|
|
raise Date.Error,text
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = int(matches[1])
|
2001-05-13 07:26:57 +05:30
|
|
|
if len(matches) == 4:
|
|
|
|
val = matches[3]
|
|
|
|
if val == None or val[0] == '?':
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = -1
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = int(val)
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = -1
|
2001-05-13 07:26:57 +05:30
|
|
|
return 1
|
2001-05-16 04:24:04 +05:30
|
|
|
|
|
|
|
match = SingleDate.fmt5.match(text)
|
|
|
|
if match != None:
|
|
|
|
matches = match.groups()
|
|
|
|
self.getMode(matches[0])
|
2001-06-17 19:10:57 +05:30
|
|
|
self.month = -1
|
|
|
|
self.day = -1
|
|
|
|
self.year = int(matches[1])
|
2001-05-16 04:24:04 +05:30
|
|
|
return 1
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2001-05-26 19:08:00 +05:30
|
|
|
match = SingleDate.fmt7.match(text)
|
|
|
|
if match != None:
|
|
|
|
matches = match.groups()
|
|
|
|
self.getMode(matches[0])
|
|
|
|
try:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.month = int(matches[1])-1
|
2001-06-22 09:01:09 +05:30
|
|
|
if self.month > 11:
|
|
|
|
raise Date.Error,text
|
|
|
|
except ValueError:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.month = -1
|
2001-05-26 19:08:00 +05:30
|
|
|
try:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = int(matches[2])
|
2001-06-22 09:01:09 +05:30
|
|
|
except ValueError:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = -1
|
2001-05-26 19:08:00 +05:30
|
|
|
return 1
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
match = SingleDate.fmt3.match(text)
|
|
|
|
if match != None:
|
|
|
|
matches = match.groups()
|
|
|
|
self.getMode(matches[0])
|
2001-05-17 18:55:28 +05:30
|
|
|
if Date.entryCode == 0:
|
2001-05-26 19:08:00 +05:30
|
|
|
try:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.month = int(matches[1])-1
|
2001-06-22 09:01:09 +05:30
|
|
|
if self.month > 11:
|
|
|
|
raise Date.Error,text
|
|
|
|
except ValueError:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.month = -1
|
2001-05-26 19:08:00 +05:30
|
|
|
try:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = int(matches[2])
|
2001-06-22 09:01:09 +05:30
|
|
|
except ValueError:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = -1
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-05-26 19:08:00 +05:30
|
|
|
try:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.month = int(matches[2])-1
|
2001-06-22 09:01:09 +05:30
|
|
|
if self.month > 11:
|
|
|
|
raise Date.Error,text
|
|
|
|
except ValueError:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.month = -1
|
2001-05-26 19:08:00 +05:30
|
|
|
try:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = int(matches[1])
|
2001-06-22 09:01:09 +05:30
|
|
|
except ValueError:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = -1
|
2001-05-17 04:51:18 +05:30
|
|
|
val = matches[3]
|
|
|
|
if val == None or val[0] == '?':
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = -1
|
2001-05-17 04:51:18 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = int(val)
|
2001-05-17 04:51:18 +05:30
|
|
|
return 1
|
|
|
|
|
|
|
|
match = SingleDate.fmt1.match(text)
|
|
|
|
if match != None:
|
|
|
|
matches = match.groups()
|
|
|
|
self.getMode(matches[0])
|
|
|
|
self.setMonthStr(matches[1])
|
2001-06-26 19:49:35 +05:30
|
|
|
if self.month == -1:
|
|
|
|
raise Date.Error,text
|
2001-05-17 04:51:18 +05:30
|
|
|
val = matches[2]
|
|
|
|
if val:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = int(string.replace(val,',',''))
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = -1
|
2001-05-17 04:51:18 +05:30
|
|
|
val = matches[3]
|
|
|
|
if val == None or val[0] == '?':
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = -1
|
2001-05-17 04:51:18 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = int(val)
|
2001-05-13 07:26:57 +05:30
|
|
|
return 1
|
|
|
|
|
|
|
|
match = SingleDate.fmt4.match(text)
|
|
|
|
if match != None:
|
|
|
|
matches = match.groups()
|
|
|
|
self.getMode(matches[0])
|
|
|
|
self.setMonthStr(matches[1])
|
2001-06-26 19:49:35 +05:30
|
|
|
if self.month == -1:
|
|
|
|
raise Date.Error,text
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = -1
|
2001-05-13 07:26:57 +05:30
|
|
|
if len(matches) == 4:
|
|
|
|
val = matches[3]
|
|
|
|
if val == None or val[0] == '?' :
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = -1
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = int(val)
|
2001-05-13 07:26:57 +05:30
|
|
|
return 1
|
|
|
|
|
|
|
|
match = SingleDate.fmt6.match(text)
|
|
|
|
if match != None:
|
|
|
|
matches = match.groups()
|
|
|
|
self.getMode(matches[0])
|
2001-06-17 19:10:57 +05:30
|
|
|
self.month = int(matches[1])-1
|
2001-06-22 09:01:09 +05:30
|
|
|
if self.month > 11:
|
|
|
|
raise Date.Error,text
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = -1
|
|
|
|
self.year = -1
|
2001-05-13 07:26:57 +05:30
|
|
|
return 1
|
|
|
|
|
2001-05-16 04:24:04 +05:30
|
|
|
raise Date.Error,text
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
def quick_set(self,text):
|
|
|
|
match = SingleDate.quick.match(text)
|
|
|
|
if match != None:
|
|
|
|
matches = match.groups()
|
|
|
|
self.setMode(matches[0])
|
2001-05-14 01:12:15 +05:30
|
|
|
self.setMonthStrEng(matches[2])
|
2001-06-26 19:49:35 +05:30
|
|
|
if self.month == -1:
|
|
|
|
raise Date.Error,text
|
2001-06-17 19:10:57 +05:30
|
|
|
self.day = int(matches[1])
|
2001-05-13 07:26:57 +05:30
|
|
|
if len(matches) == 4:
|
|
|
|
val = matches[3]
|
|
|
|
if val == None or val[0] == '?':
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = -1
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = int(val)
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = -1
|
2001-05-16 04:24:04 +05:30
|
|
|
else:
|
2001-06-17 19:10:57 +05:30
|
|
|
self.year = -1
|
|
|
|
self.month = -1
|
|
|
|
self.day = -1
|
2001-05-16 04:24:04 +05:30
|
|
|
raise Date.Error,text
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def compare_dates(f,s):
|
|
|
|
first = f.get_start_date()
|
|
|
|
second = s.get_start_date()
|
|
|
|
if first.year != second.year:
|
|
|
|
return cmp(first.year,second.year)
|
|
|
|
elif first.month != second.month:
|
|
|
|
return cmp(first.month,second.month)
|
|
|
|
else:
|
|
|
|
return cmp(first.day,second.day)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
2001-06-17 19:10:57 +05:30
|
|
|
|
|
|
|
_func = SingleDate.fmtFunc[0]
|
|
|
|
|
2001-05-17 04:51:18 +05:30
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
def checkit(s):
|
|
|
|
d = Date()
|
|
|
|
d.set(s)
|
2001-05-17 18:55:28 +05:30
|
|
|
print s, ':', d.getDate(), ':', d.getQuoteDate()
|
|
|
|
|
|
|
|
for code in range(0,7):
|
|
|
|
Date.formatCode = code
|
|
|
|
Date.entryCode = 0
|
|
|
|
print "\nFormat Code = %d\n" % code
|
|
|
|
checkit("June 11")
|
|
|
|
checkit("1923")
|
|
|
|
checkit("11/12/1293")
|
|
|
|
checkit("11 JAN 1923")
|
|
|
|
checkit("11-1-1929")
|
|
|
|
checkit("4/3/1203")
|
2001-05-26 19:08:00 +05:30
|
|
|
checkit("3/1203")
|
|
|
|
checkit("?/3/1203")
|
2001-05-17 18:55:28 +05:30
|
|
|
checkit("January 4, 1923")
|
|
|
|
checkit("before 3/3/1239")
|
|
|
|
checkit("est 2-3-1023")
|
|
|
|
checkit("between January 4, 1234 and NOV 4, 1245")
|
|
|
|
checkit("from 3-2-1234 to 5-4-2345")
|
|
|
|
Date.entryCode = 1
|
|
|
|
checkit("1/12/1999")
|
|
|
|
checkit("12/11/1999")
|
2001-06-26 19:49:35 +05:30
|
|
|
checkit("summer")
|
2001-05-17 04:51:18 +05:30
|
|
|
|
2001-06-26 19:49:35 +05:30
|
|
|
print "----------"
|
2001-06-04 07:13:11 +05:30
|
|
|
checkit("BET. 1994 - 1999")
|
2001-05-17 04:51:18 +05:30
|
|
|
|