Yaakov Nemoy napisal(a):
Hi Yaakov,
Normally, i would suggest my thoughts, but since you are considering
a
GSoC scholarship, i'm going to do this differently. I'm not going to
require it, but if you write a simple patch, i will consider it with
your application. I am curious to see how you would solve this
problem.
the easiest way would be to change this line:
match_dict['month'] = dup.parse('%s %s' % (match_dict['month'],
match_dict['year']))
in such a manner:
match_dict['month'] = dup.parse('%s 1 %s' %
(match_dict['month'],
match_dict['year']))
In this way dup.parse will create a datetime.datetime object
with its 'day' attribute set to 1 instead of the current day
number, which seems alright for me, because the 'day' attribute
is not important in this case.
A bit more complicated strategy is to set the highest number
for 'day' attribute that is possible for given year and month
in case we recive an error:
try:
match_dict['month'] = dup.parse('%s %s' %
(match_dict['month'],
match_dict['year']))
except ValueError:
import calendar
cur_month = dup.parse('1 %s' % (match_dict['month']))
max_day = calendar.monthrange(match_dict['year'], cur_month.month)[1]
match_dict['month'] = dup.parse('%s %d %s' %
(match_dict['month'],
max_day,
match_dict['year']))
But I think that there's no need to make it so complicated.
In case the first solution is not acceptable, please let me know,
I will make the second solution a bit better and I will send you
a patch then.
--
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/