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"
|
|
|
|
|
|
2001-11-02 12:25:19 +05:30
|
|
|
|
from re import IGNORECASE, compile
|
2001-05-13 07:26:57 +05:30
|
|
|
|
import string
|
|
|
|
|
|
2001-11-23 02:38:16 +05:30
|
|
|
|
from Calendar import *
|
2001-11-02 23:16:33 +05:30
|
|
|
|
from intl import gettext
|
|
|
|
|
_ = gettext
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
2001-11-21 06:46:32 +05:30
|
|
|
|
# Calendar Mappings
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
GREGORIAN = 0
|
|
|
|
|
JULIAN = 1
|
|
|
|
|
HEBREW = 2
|
|
|
|
|
FRENCH = 3
|
|
|
|
|
|
2001-11-23 11:45:22 +05:30
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# Month mappings
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
2001-11-23 02:38:16 +05:30
|
|
|
|
_fmonth = [
|
2001-11-24 21:09:02 +05:30
|
|
|
|
"Vend<EFBFBD>miaire", "Brumaire", "Frimaire", "Niv<EFBFBD>se", "Pluvi<EFBFBD>se",
|
|
|
|
|
"Vent<EFBFBD>se", "Germinal", "Flor<EFBFBD>al", "Prairial", "Messidor", "Thermidor",
|
2001-11-23 02:38:16 +05:30
|
|
|
|
"Fructidor", "Extra", ]
|
|
|
|
|
|
|
|
|
|
_fmonth2num = {
|
2001-11-24 21:09:02 +05:30
|
|
|
|
"vend" : 0, "brum" : 1, "frim" : 2, "nivo" : 3, "pluv" : 4,
|
|
|
|
|
"vent" : 5, "germ" : 6, "flor" : 7, "prai" : 8, "mess" : 9,
|
|
|
|
|
"ther" :10, "fruc" :11, "extr" : 12,"niv<EFBFBD>" : 3 }
|
2001-11-23 02:38:16 +05:30
|
|
|
|
|
|
|
|
|
_hmonth = [
|
2001-11-26 06:05:45 +05:30
|
|
|
|
"Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "AdarI",
|
2001-11-23 02:38:16 +05:30
|
|
|
|
"AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz", "Av", "Elul"
|
|
|
|
|
]
|
|
|
|
|
|
2001-11-23 11:45:22 +05:30
|
|
|
|
_hmonth2num = {
|
2001-11-26 06:05:45 +05:30
|
|
|
|
"tishri" : 0, "heshvan" : 1, "kislev" : 2, "tevet" : 3,
|
|
|
|
|
"shevat" : 4, "adari" : 5, "adarii" : 6, "nisan" : 7,
|
|
|
|
|
"iyyar" : 8, "sivan" : 9, "tammuz" :10, "av" : 11,
|
|
|
|
|
"elul" : 12,"tsh" : 0, "csh" : 1, "ksl" : 2,
|
|
|
|
|
"tvt" : 3, "shv" : 4, "adr" : 5, "ads" : 6,
|
|
|
|
|
"nsn" : 7, "iyr" : 8, "svn" : 9, "tmz" : 10,
|
|
|
|
|
"aav" :11, "ell" :12,
|
2001-11-23 11:45:22 +05:30
|
|
|
|
}
|
|
|
|
|
|
2001-11-24 21:09:02 +05:30
|
|
|
|
_mname = [ _("January"), _("February"), _("March"), _("April"),
|
|
|
|
|
_("May"), _("June"), _("July"), _("August"),
|
|
|
|
|
_("September"), _("October"), _("November"), _("December") ]
|
|
|
|
|
|
|
|
|
|
_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-11-26 06:05:45 +05:30
|
|
|
|
UNDEF = -999999
|
2001-11-23 11:45:22 +05:30
|
|
|
|
|
2001-11-21 06:46:32 +05:30
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# Date class
|
2001-05-13 07:26:57 +05:30
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
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-11-02 12:25:19 +05:30
|
|
|
|
fmt = compile(r"\s*" + from_str + r"\s+(.+)\s+" + to_str + r"\s+(.+)\s*$",
|
|
|
|
|
IGNORECASE)
|
2001-05-17 08:29:15 +05:30
|
|
|
|
|
2001-07-27 03:59:13 +05:30
|
|
|
|
def __init__(self,source=None):
|
|
|
|
|
if source:
|
|
|
|
|
self.start = SingleDate(source.start)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
if source.stop:
|
2001-07-27 03:59:13 +05:30
|
|
|
|
self.stop = SingleDate(source.stop)
|
|
|
|
|
else:
|
|
|
|
|
self.stop = None
|
|
|
|
|
self.range = source.range
|
|
|
|
|
self.text = source.text
|
2001-11-21 06:46:32 +05:30
|
|
|
|
self.calendar = source.calendar
|
2001-07-27 03:59:13 +05:30
|
|
|
|
else:
|
|
|
|
|
self.start = SingleDate()
|
|
|
|
|
self.stop = None
|
|
|
|
|
self.range = 0
|
|
|
|
|
self.text = ""
|
2001-11-21 06:46:32 +05:30
|
|
|
|
self.calendar = GREGORIAN
|
|
|
|
|
|
|
|
|
|
def get_calendar(self):
|
|
|
|
|
return self.calendar
|
|
|
|
|
|
|
|
|
|
def set_calendar(self,val):
|
|
|
|
|
self.calendar = val
|
2001-11-23 02:38:16 +05:30
|
|
|
|
self.start.convert_to(val)
|
|
|
|
|
if self.stop:
|
|
|
|
|
self.stop.convert_to(val)
|
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-11-23 02:38:16 +05:30
|
|
|
|
self.stop.calendar = self.calendar
|
2001-05-13 07:26:57 +05:30
|
|
|
|
return self.stop
|
|
|
|
|
|
2001-05-30 09:54:27 +05:30
|
|
|
|
def getYear(self):
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return self.start.year
|
2001-05-30 09:54:27 +05:30
|
|
|
|
|
2001-08-03 00:59:02 +05:30
|
|
|
|
def getHighYear(self):
|
|
|
|
|
if self.stop == None:
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return self.start.year
|
2001-08-03 00:59:02 +05:30
|
|
|
|
else:
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return self.stop.year
|
2001-08-03 00:59:02 +05:30
|
|
|
|
|
|
|
|
|
def getLowYear(self):
|
|
|
|
|
return self.start.getYear()
|
|
|
|
|
|
2001-05-30 09:54:27 +05:30
|
|
|
|
def getMonth(self):
|
2001-11-28 02:06:39 +05:30
|
|
|
|
if self.start.month == UNDEF:
|
|
|
|
|
return UNDEF
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return self.start.month+1
|
2001-05-30 09:54:27 +05:30
|
|
|
|
|
|
|
|
|
def getDay(self):
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return self.start.day
|
2001-05-30 09:54:27 +05:30
|
|
|
|
|
|
|
|
|
def getStopYear(self):
|
2001-06-20 02:18:35 +05:30
|
|
|
|
if self.stop == None:
|
|
|
|
|
self.stop = SingleDate()
|
2001-11-23 02:38:16 +05:30
|
|
|
|
self.stop.calendar = self.calendar
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return self.stop.year
|
2001-05-30 09:54:27 +05:30
|
|
|
|
|
|
|
|
|
def getStopMonth(self):
|
2001-06-20 02:18:35 +05:30
|
|
|
|
if self.stop == None:
|
|
|
|
|
self.stop = SingleDate()
|
2001-11-23 02:38:16 +05:30
|
|
|
|
self.stop.calendar = self.calendar
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return self.stop.month+1
|
2001-05-30 09:54:27 +05:30
|
|
|
|
|
|
|
|
|
def getStopDay(self):
|
2001-06-20 02:18:35 +05:30
|
|
|
|
if self.stop == None:
|
|
|
|
|
self.stop = SingleDate()
|
2001-11-23 02:38:16 +05:30
|
|
|
|
self.stop.calendar = self.calendar
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return self.stop.day
|
2001-05-30 09:54:27 +05:30
|
|
|
|
|
2001-11-21 06:46:32 +05:30
|
|
|
|
def getText(self):
|
|
|
|
|
return self.text
|
|
|
|
|
|
2001-10-27 19:40:07 +05:30
|
|
|
|
def greater_than(self,other):
|
|
|
|
|
return compare_dates(self,other) > 0
|
|
|
|
|
|
|
|
|
|
def less_than(self,other):
|
|
|
|
|
return compare_dates(self,other) < 0
|
|
|
|
|
|
|
|
|
|
def equal_to(self,other):
|
2001-11-02 02:25:44 +05:30
|
|
|
|
return compare_dates(self,other) == 0
|
2001-10-27 19:40:07 +05:30
|
|
|
|
|
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-11-23 02:38:16 +05:30
|
|
|
|
self.stop.calendar = self.calendar
|
2001-05-16 04:24:04 +05:30
|
|
|
|
self.stop.set(matches[3])
|
|
|
|
|
self.range = 1
|
|
|
|
|
else:
|
|
|
|
|
self.start.set(text)
|
|
|
|
|
self.range = 0
|
2001-11-27 07:33:18 +05:30
|
|
|
|
except Date.Error:
|
2001-05-16 04:24:04 +05:30
|
|
|
|
self.range = -1
|
|
|
|
|
self.text = text
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
2001-11-21 06:46:32 +05:30
|
|
|
|
def set_range(self,val):
|
|
|
|
|
self.range = val
|
|
|
|
|
|
2001-11-23 11:45:22 +05:30
|
|
|
|
def get_fmt(self,func):
|
2001-06-17 19:10:57 +05:30
|
|
|
|
if self.range == 0:
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return func(self.start)
|
2001-05-16 04:24:04 +05:30
|
|
|
|
elif self.range == -1:
|
|
|
|
|
return self.text
|
|
|
|
|
else:
|
2001-11-23 11:45:22 +05:30
|
|
|
|
d1 = func(self.start)
|
|
|
|
|
d2 = func(self.stop)
|
2001-11-21 06:46:32 +05:30
|
|
|
|
return "%s %s %s %s" % ( _("from"),d1,_("to"),d2 )
|
2001-11-23 11:45:22 +05:30
|
|
|
|
|
|
|
|
|
def getDate(self):
|
|
|
|
|
return self.get_fmt(SingleDate.getDate)
|
2001-05-16 04:24:04 +05:30
|
|
|
|
|
2001-11-23 02:38:16 +05:30
|
|
|
|
def getQuoteDate(self):
|
|
|
|
|
if self.calendar == GREGORIAN:
|
|
|
|
|
return self.getGregorianQuoteDate()
|
|
|
|
|
elif self.calendar == JULIAN:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return self.get_quote_date(_mname,_("Julian"))
|
2001-11-23 02:38:16 +05:30
|
|
|
|
elif self.calendar == HEBREW:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
return self.get_quote_date(_hmonth,_("Hebrew"))
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return self.get_quote_date(_fmonth,_("French"))
|
2001-11-23 02:38:16 +05:30
|
|
|
|
|
|
|
|
|
def getGregorianQuoteDate(self):
|
|
|
|
|
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-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-21 06:46:32 +05:30
|
|
|
|
d1 = _func(self.start)
|
|
|
|
|
d2 = _func(self.stop)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
return "%s %s %s %s" % ( _("from"),d1,_("to"), d2)
|
|
|
|
|
|
2001-11-24 21:09:02 +05:30
|
|
|
|
def get_quote_date(self,month_map,cal_str):
|
2001-11-23 02:38:16 +05:30
|
|
|
|
if self.range == 0:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return "%s (%s)" % (self.start.display_calendar(month_map),cal_str)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
elif self.range == -1:
|
|
|
|
|
if self.text:
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return '"%s (%s)"' % (self.text,cal_str)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return ''
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
d1 = self.start.display_calendar(month_map)
|
2001-11-25 10:08:30 +05:30
|
|
|
|
d2 = self.stop.display_calendar(month_map)
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return "%s %s %s %s (%s)" % ( _("from"),d1,_("to"), d2,cal_str)
|
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
def getSaveDate(self):
|
2001-05-16 04:24:04 +05:30
|
|
|
|
if self.range == 1:
|
2001-11-21 06:46:32 +05:30
|
|
|
|
d1 = self.start.getSaveDate()
|
|
|
|
|
d2 = self.stop.getSaveDate()
|
|
|
|
|
return "FROM %s TO %s" % (d1,d2)
|
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):
|
2001-11-23 11:45:22 +05:30
|
|
|
|
s = self.start
|
2001-11-26 06:05:45 +05:30
|
|
|
|
return s.year==UNDEF and s.month==UNDEF and s.day==UNDEF
|
2001-05-18 04:41:23 +05:30
|
|
|
|
|
|
|
|
|
def isValid(self):
|
2001-11-26 06:05:45 +05:30
|
|
|
|
return self.range != -1
|
2001-05-20 00:11:47 +05:30
|
|
|
|
|
|
|
|
|
def isRange(self):
|
2001-11-23 11:45:22 +05:30
|
|
|
|
return self.range == 1
|
2001-05-18 04:41:23 +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 08:13:10 +05:30
|
|
|
|
emname =[ 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
|
|
|
|
|
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC' ]
|
|
|
|
|
|
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-12-04 10:56:01 +05:30
|
|
|
|
_("aft") : after,
|
|
|
|
|
# And the untranslated versions for backward compatability
|
|
|
|
|
"abt" : about,
|
|
|
|
|
"after" : after,
|
|
|
|
|
"before" : before }
|
2001-05-14 01:12:15 +05:30
|
|
|
|
|
|
|
|
|
modifiers = "(" + \
|
2001-11-25 10:08:30 +05:30
|
|
|
|
_("abt\.?") + '|' + \
|
2001-05-14 01:12:15 +05:30
|
|
|
|
_("about") + '|' + \
|
2001-11-25 10:08:30 +05:30
|
|
|
|
_("est\.?") + '|' + \
|
2001-05-14 01:12:15 +05:30
|
|
|
|
_("circa") + '|' + \
|
|
|
|
|
_("around") + '|' + \
|
|
|
|
|
_("before") + '|' + \
|
|
|
|
|
_("after") + '|' + \
|
2001-11-25 10:08:30 +05:30
|
|
|
|
_("aft\.?") + '|' + \
|
|
|
|
|
_("bef\.?") + '|' + \
|
2001-11-19 05:09:34 +05:30
|
|
|
|
"abt" + '|' + \
|
|
|
|
|
"aft" + '|' + \
|
|
|
|
|
"bef" + ')'
|
2001-05-14 01:12:15 +05:30
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
start = "^\s*" + modifiers + "?\s*"
|
|
|
|
|
|
2001-11-02 12:25:19 +05:30
|
|
|
|
fmt1 = compile(start + "(\S+)(\s+\d+\s*,)?\s*(\d+)?\s*$", IGNORECASE)
|
|
|
|
|
fmt2 = compile(start + "(\d+)\.?\s+(\S+)(\s+\d+)?\s*$", IGNORECASE)
|
|
|
|
|
quick= compile(start + "(\d+)?\s(\S\S\S)?\s(\d+)?", IGNORECASE)
|
|
|
|
|
fmt3 = compile(start + r"([?\d]+)\s*[./-]\s*([?\d]+)\s*[./-]\s*([?\d]+)\s*$",
|
|
|
|
|
IGNORECASE)
|
|
|
|
|
fmt7 = compile(start + r"([?\d]+)\s*[./-]\s*([?\d]+)\s*$", IGNORECASE)
|
|
|
|
|
fmt4 = compile(start + "(\S+)\s+(\d+)\s*$", IGNORECASE)
|
|
|
|
|
fmt5 = compile(start + "(\d+)\s*$", IGNORECASE)
|
|
|
|
|
fmt6 = compile(start + "(\S+)\s*$", IGNORECASE)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
2001-07-27 03:59:13 +05:30
|
|
|
|
def __init__(self,source=None):
|
|
|
|
|
if source:
|
|
|
|
|
self.month = source.month
|
|
|
|
|
self.day = source.day
|
|
|
|
|
self.year = source.year
|
|
|
|
|
self.mode = source.mode
|
2001-11-23 02:38:16 +05:30
|
|
|
|
self.calendar = source.calendar
|
2001-07-27 03:59:13 +05:30
|
|
|
|
else:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.month = UNDEF
|
|
|
|
|
self.day = UNDEF
|
|
|
|
|
self.year = UNDEF
|
2001-07-27 03:59:13 +05:30
|
|
|
|
self.mode = SingleDate.exact
|
2001-11-23 02:38:16 +05:30
|
|
|
|
self.calendar = GREGORIAN
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
|
|
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-11-24 21:09:02 +05:30
|
|
|
|
if val > 12 or val < 0:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.month = UNDEF
|
2001-06-22 05:25:59 +05:30
|
|
|
|
else:
|
|
|
|
|
self.month = val - 1
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
2001-11-24 21:09:02 +05:30
|
|
|
|
def setMonthVal(self,s):
|
|
|
|
|
try:
|
|
|
|
|
val = int(s)
|
|
|
|
|
self.month = val - 1
|
|
|
|
|
except ValueError:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.month = UNDEF
|
2001-11-24 21:09:02 +05:30
|
|
|
|
|
|
|
|
|
def setDayVal(self,s):
|
|
|
|
|
try:
|
|
|
|
|
val = int(s)
|
|
|
|
|
self.day = val
|
|
|
|
|
except ValueError:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.day = UNDEF
|
2001-11-24 21:09:02 +05:30
|
|
|
|
|
|
|
|
|
def setYearVal(self,s):
|
|
|
|
|
try:
|
|
|
|
|
val = int(s)
|
|
|
|
|
self.year = val
|
|
|
|
|
except ValueError:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.year = UNDEF
|
2001-11-24 21:09:02 +05:30
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
def getMonth(self):
|
2001-11-28 02:06:39 +05:30
|
|
|
|
if self.month == UNDEF:
|
|
|
|
|
return UNDEF
|
2001-05-13 07:26:57 +05:30
|
|
|
|
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-11-27 07:33:18 +05:30
|
|
|
|
self.month = _m2num[string.lower(text[0:3])]
|
2001-06-26 19:49:35 +05:30
|
|
|
|
except KeyError:
|
2001-07-28 07:46:20 +05:30
|
|
|
|
self.setMonthStrEng(text)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
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-11-26 06:05:45 +05:30
|
|
|
|
self.month = UNDEF
|
2001-05-14 01:12:15 +05:30
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
def getMonthStr(self):
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return _mname[self.month]
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
2001-11-21 06:46:32 +05:30
|
|
|
|
def getIsoDate(self):
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
y = "????"
|
2001-11-21 06:46:32 +05:30
|
|
|
|
else:
|
|
|
|
|
y = "%04d" % self.year
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF:
|
|
|
|
|
if self.day == UNDEF:
|
2001-11-21 06:46:32 +05:30
|
|
|
|
m = ""
|
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
m = "-??"
|
2001-11-21 06:46:32 +05:30
|
|
|
|
else:
|
|
|
|
|
m = "-%02d" % (self.month+1)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.day == UNDEF:
|
2001-11-21 06:46:32 +05:30
|
|
|
|
d = ''
|
|
|
|
|
else:
|
|
|
|
|
d = "-%02d" % self.day
|
|
|
|
|
return "%s%s%s" % (y,m,d)
|
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
def getSaveDate(self):
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
|
2001-11-28 06:39:27 +05:30
|
|
|
|
return ""
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
|
|
|
|
if self.month == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
retval = str(self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.year == UNDEF:
|
2001-05-17 08:13:10 +05:30
|
|
|
|
retval = SingleDate.emname[self.month]
|
|
|
|
|
else:
|
|
|
|
|
retval = "%s %d" % (SingleDate.emname[self.month],self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.month == UNDEF:
|
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]
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
2001-05-17 08:13:10 +05:30
|
|
|
|
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-11-24 21:09:02 +05:30
|
|
|
|
elif self.mode == SingleDate.before:
|
2001-11-21 06:46:32 +05:30
|
|
|
|
retval = "BEFORE" + " " + retval
|
2001-05-17 08:13:10 +05:30
|
|
|
|
elif self.mode == SingleDate.after:
|
2001-11-21 06:46:32 +05:30
|
|
|
|
retval = "AFTER" + " " + retval
|
2001-05-17 08:13:10 +05:30
|
|
|
|
return retval
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt1(self):
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
|
2001-06-17 19:10:57 +05:30
|
|
|
|
return ""
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
|
|
|
|
if self.month == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
retval = str(self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.year == UNDEF:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
retval = _mname[self.month]
|
2001-05-13 07:26:57 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
retval = "%s %d" % (_mname[self.month],self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.month == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
retval = str(self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
month = _mname[self.month]
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
2001-05-13 07:26:57 +05:30
|
|
|
|
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-11-24 21:09:02 +05:30
|
|
|
|
elif 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
|
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt2(self):
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
|
2001-06-17 19:10:57 +05:30
|
|
|
|
return ""
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.month != UNDEF and self.month != UNDEF:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
month = _mname[self.month]
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
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-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
|
|
|
|
if self.month == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
retval = str(self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.year == UNDEF:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
month = _mname[self.month]
|
2001-05-13 07:26:57 +05:30
|
|
|
|
retval = string.upper(month[0:3])
|
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
month = _mname[self.month]
|
2001-05-13 07:26:57 +05:30
|
|
|
|
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-11-24 21:09:02 +05:30
|
|
|
|
elif 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
|
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt3(self):
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return ""
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
|
|
|
|
if self.month == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
retval = str(self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.year == UNDEF:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
month = _mname[self.month]
|
2001-05-13 07:26:57 +05:30
|
|
|
|
retval = string.upper(month[0:3])
|
2001-06-22 05:25:59 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
month = _mname[self.month]
|
2001-05-13 07:26:57 +05:30
|
|
|
|
retval = "%s %d" % (string.upper(month[0:3]),self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.month == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
retval = str(self.year)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
month = _mname[self.month]
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
2001-05-13 07:26:57 +05:30
|
|
|
|
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-11-24 21:09:02 +05:30
|
|
|
|
elif 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-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt10(self):
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return ""
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
|
|
|
|
if self.month == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
retval = str(self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.year == UNDEF:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
retval = _mname[self.month]
|
2001-05-17 18:55:28 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
month = _mname[self.month]
|
2001-07-01 04:31:38 +05:30
|
|
|
|
retval = "%s %d" % (month,self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.month == UNDEF:
|
2001-07-01 04:31:38 +05:30
|
|
|
|
retval = str(self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
month = _mname[self.month]
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
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-11-24 21:09:02 +05:30
|
|
|
|
elif 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-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return ""
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
|
|
|
|
if self.month == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
retval = str(self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.year == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "%02d%s??%s??" % (self.month+1,sep,sep)
|
2001-05-17 18:55:28 +05:30
|
|
|
|
else:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "%02d%s??%s%04d" % (self.month+1,sep,sep,self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.month == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "??%s%02d%s%04d" % (sep,self.day,sep,self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
else:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "%02d%s%02d%s????" % (self.month+1,sep,self.day,sep)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
else:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "%02d%s%02d%s%04d" % (self.month+1,sep,self.day,sep,self.year)
|
|
|
|
|
|
|
|
|
|
if self.mode == SingleDate.about:
|
|
|
|
|
retval = "%s %s" % (_("ABT"),retval)
|
2001-11-24 21:09:02 +05:30
|
|
|
|
elif self.mode == SingleDate.before:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "%s %s" % (_("BEFORE"),retval)
|
|
|
|
|
elif self.mode == SingleDate.after:
|
|
|
|
|
retval = "%s %s" % (_("AFTER"),retval)
|
|
|
|
|
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
|
|
def get_yyyymmdd(self,sep):
|
|
|
|
|
retval = ""
|
|
|
|
|
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
|
2001-07-13 05:31:04 +05:30
|
|
|
|
pass
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
|
|
|
|
if self.month == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = str(self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.year == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "????%s%02d%s??" % (sep,self.month+1,sep)
|
|
|
|
|
else:
|
2001-11-01 08:27:11 +05:30
|
|
|
|
retval = "%04d%s%02d" % (self.year,sep,self.month+1)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.month == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "%04d%s??%s%02d" % (self.year,sep,sep,self.day)
|
|
|
|
|
else:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "????%02d%s%02d%s" % (self.month+1,sep,self.day,sep)
|
|
|
|
|
else:
|
|
|
|
|
retval = "%02d%s%02d%s%02d" % (self.year,sep,self.month+1,sep,self.day)
|
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-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt4(self):
|
2001-07-01 04:31:38 +05:30
|
|
|
|
return self.get_mmddyyyy("/")
|
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt5(self):
|
2001-07-01 04:31:38 +05:30
|
|
|
|
return self.get_mmddyyyy("-")
|
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt8(self):
|
2001-07-01 04:31:38 +05:30
|
|
|
|
return self.get_mmddyyyy(".")
|
|
|
|
|
|
|
|
|
|
def get_ddmmyyyy(self,sep):
|
2001-05-13 07:26:57 +05:30
|
|
|
|
retval = ""
|
|
|
|
|
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
|
2001-05-13 07:26:57 +05:30
|
|
|
|
pass
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
|
|
|
|
if self.month == UNDEF:
|
2001-06-17 19:10:57 +05:30
|
|
|
|
retval = str(self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.year == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "??%s%02d%s??" % (sep,self.month+1,sep)
|
2001-05-17 18:55:28 +05:30
|
|
|
|
else:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "??%s%02d%s%04d" % (sep,self.month+1,sep,self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.month == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "%02d%s??%s%04d" % (self.day,sep,sep,self.year)
|
2001-05-17 04:51:18 +05:30
|
|
|
|
else:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "%02d%s%02d%s????" % (self.day,sep,self.month+1,sep)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
else:
|
2001-07-13 05:31:04 +05:30
|
|
|
|
retval = "%02d%s%02d%s%04d" % (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-11-23 02:38:16 +05:30
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt6(self):
|
2001-07-01 04:31:38 +05:30
|
|
|
|
return self.get_ddmmyyyy("/")
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt7(self):
|
2001-07-01 04:31:38 +05:30
|
|
|
|
return self.get_ddmmyyyy("-")
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt9(self):
|
2001-07-01 04:31:38 +05:30
|
|
|
|
return self.get_ddmmyyyy(".")
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt11(self):
|
2001-07-13 05:31:04 +05:30
|
|
|
|
return self.get_yyyymmdd("/")
|
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt12(self):
|
2001-07-13 05:31:04 +05:30
|
|
|
|
return self.get_yyyymmdd("-")
|
|
|
|
|
|
2001-11-28 06:39:27 +05:30
|
|
|
|
def get_fmt13(self):
|
2001-07-13 05:31:04 +05:30
|
|
|
|
return self.get_yyyymmdd(".")
|
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#--------------------------------------------------------------------
|
2001-11-28 06:39:27 +05:30
|
|
|
|
fmtFunc = [ get_fmt1, get_fmt2, get_fmt3, get_fmt4, get_fmt5, get_fmt6,
|
|
|
|
|
get_fmt7, get_fmt8, get_fmt9, get_fmt10, get_fmt11, get_fmt12,
|
|
|
|
|
get_fmt13]
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
2001-11-24 21:09:02 +05:30
|
|
|
|
def display_calendar(self,month_map):
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year==UNDEF:
|
|
|
|
|
if self.month == UNDEF:
|
2001-11-23 02:38:16 +05:30
|
|
|
|
return ""
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return month_map[self.month]
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-28 06:39:27 +05:30
|
|
|
|
return "%02d %s" % (self.day,month_map[self.month])
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.month == UNDEF:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return str(self.year)
|
2001-11-26 06:05:45 +05:30
|
|
|
|
elif self.day == UNDEF:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return "%s %d" % (month_map[self.month],self.year)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return "%02d %s %d" % (self.day,month_map[self.month],self.year)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
def getDate(self):
|
2001-11-23 02:38:16 +05:30
|
|
|
|
if self.calendar == GREGORIAN:
|
|
|
|
|
return _func(self)
|
|
|
|
|
elif self.calendar == JULIAN:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return self.display_calendar(_mname)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
elif self.calendar == HEBREW:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return self.display_calendar(_hmonth)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
return self.display_calendar(_fmonth)
|
|
|
|
|
|
2001-11-21 06:46:32 +05:30
|
|
|
|
def setIsoDate(self,v):
|
|
|
|
|
data = string.split(v)
|
|
|
|
|
if len(data) > 1:
|
|
|
|
|
self.setMode(data[0])
|
|
|
|
|
v = data[1]
|
|
|
|
|
|
|
|
|
|
vals = string.split(v,'-')
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setYearVal(vals[0])
|
|
|
|
|
if len(vals) > 1:
|
|
|
|
|
self.setMonthVal(vals[1])
|
2001-11-21 06:46:32 +05:30
|
|
|
|
if len(vals) > 2:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setDayVal(vals[2])
|
2001-11-21 06:46:32 +05:30
|
|
|
|
|
|
|
|
|
def getModeVal(self):
|
|
|
|
|
return self.mode
|
|
|
|
|
|
|
|
|
|
def setModeVal(self,val):
|
|
|
|
|
self.mode = val
|
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
def set(self,text):
|
2001-11-23 02:38:16 +05:30
|
|
|
|
if self.calendar == GREGORIAN:
|
|
|
|
|
self.set_gregorian(text)
|
|
|
|
|
elif self.calendar == JULIAN:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.set_calendar(text,_m2num,3)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
elif self.calendar == HEBREW:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.set_calendar(text,_hmonth2num,0)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.set_calendar(text,_fmonth2num,4)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
|
2001-11-24 21:09:02 +05:30
|
|
|
|
def set_calendar(self,text,month_map,l):
|
2001-11-23 02:38:16 +05:30
|
|
|
|
match = SingleDate.fmt2.match(text)
|
|
|
|
|
if match:
|
|
|
|
|
matches = match.groups()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-11-24 21:09:02 +05:30
|
|
|
|
if l == 0:
|
|
|
|
|
mon = string.lower(matches[2])
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
mon = string.lower(matches[2])[0:l]
|
|
|
|
|
if month_map.has_key(mon):
|
2001-11-23 02:38:16 +05:30
|
|
|
|
self.setYear(int(matches[3]))
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setMonth(month_map[mon]+1)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
self.setDay(int(matches[1]))
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
self.setYear(int(matches[3]))
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.setMonth(UNDEF)
|
|
|
|
|
self.setDay(UNDEF)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
return
|
|
|
|
|
match = SingleDate.fmt3.match(text)
|
|
|
|
|
if match:
|
|
|
|
|
matches = match.groups()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setYearVal(matches[3])
|
|
|
|
|
self.setMonthVal(matches[2])
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.setDayVal(matches[1])
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
match = SingleDate.fmt4.match(text)
|
|
|
|
|
if match:
|
|
|
|
|
matches = match.groups()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if l == 0:
|
|
|
|
|
mon = string.lower(matches[1])
|
|
|
|
|
else:
|
|
|
|
|
mon = string.lower(matches[1])[0:l]
|
|
|
|
|
self.setYearVal(matches[2])
|
|
|
|
|
self.setMonth(month_map[mon]+1)
|
|
|
|
|
self.day = UNDEF
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
match = SingleDate.fmt5.match(text)
|
|
|
|
|
if match:
|
|
|
|
|
matches = match.groups()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.setYearVal(matches[1])
|
|
|
|
|
self.month = UNDEF
|
|
|
|
|
self.day = UNDEF
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
self.year = UNDEF
|
|
|
|
|
self.month = UNDEF
|
|
|
|
|
self.day = UNDEF
|
2001-11-23 02:38:16 +05:30
|
|
|
|
|
|
|
|
|
def set_gregorian(self,text):
|
2001-05-13 07:26:57 +05:30
|
|
|
|
match = SingleDate.fmt2.match(text)
|
|
|
|
|
if match != None:
|
|
|
|
|
matches = match.groups()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-05-13 07:26:57 +05:30
|
|
|
|
self.setMonthStr(matches[2])
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF:
|
2001-06-26 19:49:35 +05:30
|
|
|
|
raise Date.Error,text
|
2001-06-17 19:10:57 +05:30
|
|
|
|
self.day = int(matches[1])
|
2001-12-01 09:53:42 +05:30
|
|
|
|
if len(matches) == 4 and matches[3] != None:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setYearVal(matches[3])
|
2001-05-13 07:26:57 +05:30
|
|
|
|
else:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.year = UNDEF
|
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()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.month = UNDEF
|
|
|
|
|
self.day = UNDEF
|
2001-06-17 19:10:57 +05:30
|
|
|
|
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()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-11-01 08:27:11 +05:30
|
|
|
|
if Date.entryCode == 2:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setMonthVal(matches[2])
|
|
|
|
|
self.setYearVal(matches[1])
|
2001-11-01 08:27:11 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setMonthVal(matches[1])
|
|
|
|
|
self.setYearVal(matches[2])
|
|
|
|
|
return 1
|
2001-05-26 19:08:00 +05:30
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
match = SingleDate.fmt3.match(text)
|
|
|
|
|
if match != None:
|
|
|
|
|
matches = match.groups()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-05-17 18:55:28 +05:30
|
|
|
|
if Date.entryCode == 0:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setMonthVal(matches[1])
|
|
|
|
|
self.setDayVal(matches[2])
|
|
|
|
|
self.setYearVal(matches[3])
|
2001-07-13 05:31:04 +05:30
|
|
|
|
elif Date.entryCode == 1:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setMonthVal(matches[2])
|
|
|
|
|
self.setDayVal(matches[1])
|
|
|
|
|
self.setYearVal(matches[3])
|
2001-05-17 04:51:18 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setMonthVal(matches[2])
|
|
|
|
|
self.setDayVal(matches[3])
|
|
|
|
|
self.setYearVal(matches[1])
|
2001-05-17 04:51:18 +05:30
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
match = SingleDate.fmt1.match(text)
|
|
|
|
|
if match != None:
|
|
|
|
|
matches = match.groups()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-05-17 04:51:18 +05:30
|
|
|
|
self.setMonthStr(matches[1])
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF:
|
2001-06-26 19:49:35 +05:30
|
|
|
|
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-11-26 06:05:45 +05:30
|
|
|
|
self.day = UNDEF
|
2001-11-30 02:37:56 +05:30
|
|
|
|
val = matches[3]
|
|
|
|
|
if val:
|
|
|
|
|
self.setYearVal(matches[3])
|
|
|
|
|
else:
|
|
|
|
|
self.setYearVal(UNDEF)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
match = SingleDate.fmt4.match(text)
|
|
|
|
|
if match != None:
|
|
|
|
|
matches = match.groups()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-05-13 07:26:57 +05:30
|
|
|
|
self.setMonthStr(matches[1])
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF:
|
2001-06-26 19:49:35 +05:30
|
|
|
|
raise Date.Error,text
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.day = UNDEF
|
2001-05-13 07:26:57 +05:30
|
|
|
|
if len(matches) == 4:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setYearVal(matches[3])
|
2001-05-13 07:26:57 +05:30
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
match = SingleDate.fmt6.match(text)
|
|
|
|
|
if match != None:
|
|
|
|
|
matches = match.groups()
|
2001-11-27 07:33:18 +05:30
|
|
|
|
self.setMode(matches[0])
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.setMonthVal(matches[1])
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.day = UNDEF
|
|
|
|
|
self.year = UNDEF
|
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
|
|
|
|
|
2001-11-23 02:38:16 +05:30
|
|
|
|
def get_sdn(self):
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.year == UNDEF:
|
2001-11-23 02:38:16 +05:30
|
|
|
|
return 0
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.month == UNDEF:
|
2001-11-23 02:38:16 +05:30
|
|
|
|
month = 1
|
2001-05-16 04:24:04 +05:30
|
|
|
|
else:
|
2001-11-23 02:38:16 +05:30
|
|
|
|
month = self.month + 1
|
2001-11-26 06:05:45 +05:30
|
|
|
|
if self.day == UNDEF:
|
2001-11-23 02:38:16 +05:30
|
|
|
|
day = 1
|
|
|
|
|
else:
|
|
|
|
|
day = self.day
|
|
|
|
|
|
|
|
|
|
if self.calendar == GREGORIAN:
|
|
|
|
|
sdn = gregorian_to_sdn(self.year,month,day)
|
|
|
|
|
elif self.calendar == FRENCH:
|
|
|
|
|
sdn = french_to_sdn(self.year,month,day)
|
|
|
|
|
if self.calendar == HEBREW:
|
|
|
|
|
sdn = jewish_to_sdn(self.year,month,day)
|
|
|
|
|
if self.calendar == JULIAN:
|
|
|
|
|
sdn = julian_to_sdn(self.year,month,day)
|
|
|
|
|
return sdn
|
|
|
|
|
|
|
|
|
|
def convert_to(self,val):
|
|
|
|
|
if val == GREGORIAN:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.convert_calendar(sdn_to_gregorian,val)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
elif val == JULIAN:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.convert_calendar(sdn_to_julian,val)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
elif val == HEBREW:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.convert_calendar(sdn_to_jewish,val)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
2001-11-24 21:09:02 +05:30
|
|
|
|
self.convert_calendar(sdn_to_french,val)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
|
2001-11-24 21:09:02 +05:30
|
|
|
|
def convert_calendar(self,func,mode):
|
2001-11-23 02:38:16 +05:30
|
|
|
|
sdn = self.get_sdn()
|
2001-11-24 21:09:02 +05:30
|
|
|
|
(y,m,d) = func(sdn)
|
|
|
|
|
self.calendar = mode
|
2001-11-23 02:38:16 +05:30
|
|
|
|
if y == 0 and m == 0 and d == 0:
|
2001-11-26 06:05:45 +05:30
|
|
|
|
self.year = UNDEF
|
|
|
|
|
self.month = UNDEF
|
|
|
|
|
self.day = UNDEF
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
|
|
|
|
self.year = y
|
|
|
|
|
self.month = m-1
|
|
|
|
|
self.day = d
|
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
def compare_dates(f,s):
|
2001-11-23 02:38:16 +05:30
|
|
|
|
if f.calendar != s.calendar:
|
|
|
|
|
return 1
|
2001-11-01 08:45:41 +05:30
|
|
|
|
if f.range == -1 and s.range == -1:
|
|
|
|
|
return cmp(f.text,s.text)
|
|
|
|
|
if f.range == -1 or s.range == -1:
|
|
|
|
|
return -1
|
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
|
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)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
elif f.range != 1:
|
2001-05-13 07:26:57 +05:30
|
|
|
|
return cmp(first.day,second.day)
|
2001-11-23 02:38:16 +05:30
|
|
|
|
else:
|
|
|
|
|
first = f.get_stop_date()
|
|
|
|
|
second = s.get_stop_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-11-23 02:38:16 +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")
|