I need to search characters inside a date string so that I can split the string.
date = '02/03/2010'
The date separators could be ('/', ' ', '-', '.')
date = '02/03/2010'
The date separators could be ('/', ' ', '-', '.')
class Date:
"""Class for storing dates"""
MONTHNAMES = ['January', 'February', 'March', 'April',
'May', 'June', 'July', 'August', 'September', 'October',
'November', 'December']
MONTHLENGTHS = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']
def __init__(self, date):
'''Constructor'''
self._date = date
self._date = self.convertDate() #convert the date to the proper format
def __str__(self):
'''Display the date in Month XX, YYYY format'''
#pass
return self._date
def convertDate(self):
'''Converts the given date into format Month XX, YYYY format'''
#pass
parts = self.dateParts()
if not parts[0] in Date.MONTHNAMES:
parts[0] = Date.MONTHNAMES[int(parts[0])-1]
date = parts[0] + ' ' + parts[1] + ', ' + parts[2]
return date
def dateParts(self):
'''Separates the date into parts: month, day, and year.'''
separators = ('/', ' ', '.', '-', ',')
dateParts = re.split("[%s]" % (''.join(separators)),self._date) #import re for this command to work
return dateParts
separators = (',', '/', ' ', '.', '-')
Comment