def _evalModifier(self, modifier, chunk1, chunk2, sourceTime):
ctx = self.currentContext<EOL>offset = self.ptc.Modifiers[modifier]<EOL>if sourceTime is not None:<EOL><INDENT>(yr, mth, dy, hr, mn, sec, wd, yd, isdst) = sourceTime<EOL><DEDENT>else:<EOL><INDENT>(yr, mth, dy, hr, mn, sec, wd, yd, isdst) = time.localtime()<EOL><DEDENT>if self.ptc.StartTimeFromSourceTime:<EOL><INDENT>startHour = hr<EOL>startMinute = mn<EOL>startSecond = sec<EOL><DEDENT>else:<EOL><INDENT>startHour = <NUM_LIT:9><EOL>startMinute = <NUM_LIT:0><EOL>startSecond = <NUM_LIT:0><EOL><DEDENT>m = self.ptc.CRE_REMAINING.search(chunk2)<EOL>if m is not None:<EOL><INDENT>index = m.start() + <NUM_LIT:1><EOL>unit = chunk2[:m.start()]<EOL>chunk2 = chunk2[index:]<EOL><DEDENT>else:<EOL><INDENT>unit = chunk2<EOL>chunk2 = '<STR_LIT>'<EOL><DEDENT>debug and log.debug("<STR_LIT>"<EOL>"<STR_LIT>",<EOL>modifier, chunk1, chunk2, unit)<EOL>if unit in self.ptc.units['<STR_LIT>']:<EOL><INDENT>currentDaysInMonth = self.ptc.daysInMonth(mth, yr)<EOL>if offset == <NUM_LIT:0>:<EOL><INDENT>dy = currentDaysInMonth<EOL>sourceTime = (yr, mth, dy, startHour, startMinute,<EOL>startSecond, wd, yd, isdst)<EOL><DEDENT>elif offset == <NUM_LIT:2>:<EOL><INDENT>if dy == currentDaysInMonth:<EOL><INDENT>dy = self.ptc.daysInMonth(mth + <NUM_LIT:1>, yr)<EOL><DEDENT>start = datetime.datetime(yr, mth, dy, startHour,<EOL>startMinute, startSecond)<EOL>target = self.inc(start, month=<NUM_LIT:1>)<EOL>sourceTime = target.timetuple()<EOL><DEDENT>else:<EOL><INDENT>start = datetime.datetime(yr, mth, <NUM_LIT:1>, startHour,<EOL>startMinute, startSecond)<EOL>target = self.inc(start, month=offset)<EOL>sourceTime = target.timetuple()<EOL><DEDENT>ctx.updateAccuracy(ctx.ACU_MONTH)<EOL><DEDENT>elif unit in self.ptc.units['<STR_LIT>']:<EOL><INDENT>if offset == <NUM_LIT:0>:<EOL><INDENT>start = datetime.datetime(yr, mth, dy, <NUM_LIT>, <NUM_LIT:0>, <NUM_LIT:0>)<EOL>target = start + datetime.timedelta(days=(<NUM_LIT:4> - wd))<EOL>sourceTime = target.timetuple()<EOL><DEDENT>elif offset == <NUM_LIT:2>:<EOL><INDENT>start = datetime.datetime(yr, mth, dy, startHour,<EOL>startMinute, startSecond)<EOL>target = start + datetime.timedelta(days=<NUM_LIT:7>)<EOL>sourceTime = target.timetuple()<EOL><DEDENT>else:<EOL><INDENT>start = datetime.datetime(yr, mth, dy, startHour,<EOL>startMinute, startSecond)<EOL>target = start + offset * datetime.timedelta(weeks=<NUM_LIT:1>)<EOL>sourceTime = target.timetuple()<EOL><DEDENT>ctx.updateAccuracy(ctx.ACU_WEEK)<EOL><DEDENT>elif unit in self.ptc.units['<STR_LIT>']:<EOL><INDENT>if offset == <NUM_LIT:0>:<EOL><INDENT>sourceTime = (yr, mth, dy, <NUM_LIT>, <NUM_LIT:0>, <NUM_LIT:0>, wd, yd, isdst)<EOL>ctx.updateAccuracy(ctx.ACU_HALFDAY)<EOL><DEDENT>elif offset == <NUM_LIT:2>:<EOL><INDENT>start = datetime.datetime(yr, mth, dy, hr, mn, sec)<EOL>target = start + datetime.timedelta(days=<NUM_LIT:1>)<EOL>sourceTime = target.timetuple()<EOL><DEDENT>else:<EOL><INDENT>start = datetime.datetime(yr, mth, dy, startHour,<EOL>startMinute, startSecond)<EOL>target = start + datetime.timedelta(days=offset)<EOL>sourceTime = target.timetuple()<EOL><DEDENT>ctx.updateAccuracy(ctx.ACU_DAY)<EOL><DEDENT>elif unit in self.ptc.units['<STR_LIT>']:<EOL><INDENT>if offset == <NUM_LIT:0>:<EOL><INDENT>sourceTime = (yr, mth, dy, hr, <NUM_LIT:0>, <NUM_LIT:0>, wd, yd, isdst)<EOL><DEDENT>else:<EOL><INDENT>start = datetime.datetime(yr, mth, dy, hr, <NUM_LIT:0>, <NUM_LIT:0>)<EOL>target = start + datetime.timedelta(hours=offset)<EOL>sourceTime = target.timetuple()<EOL><DEDENT>ctx.updateAccuracy(ctx.ACU_HOUR)<EOL><DEDENT>elif unit in self.ptc.units['<STR_LIT>']:<EOL><INDENT>if offset == <NUM_LIT:0>:<EOL><INDENT>sourceTime = (yr, <NUM_LIT:12>, <NUM_LIT>, hr, mn, sec, wd, yd, isdst)<EOL><DEDENT>elif offset == <NUM_LIT:2>:<EOL><INDENT>sourceTime = (yr + <NUM_LIT:1>, mth, dy, hr, mn, sec, wd, yd, isdst)<EOL><DEDENT>else:<EOL><INDENT>sourceTime = (yr + offset, <NUM_LIT:1>, <NUM_LIT:1>, startHour, startMinute,<EOL>startSecond, wd, yd, isdst)<EOL><DEDENT>ctx.updateAccuracy(ctx.ACU_YEAR)<EOL><DEDENT>elif modifier == '<STR_LIT>':<EOL><INDENT>dy = self.ptc.daysInMonth(mth, yr)<EOL>sourceTime = (yr, mth, dy, startHour, startMinute,<EOL>startSecond, wd, yd, isdst)<EOL>ctx.updateAccuracy(ctx.ACU_DAY)<EOL><DEDENT>elif modifier == '<STR_LIT>':<EOL><INDENT>mth = <NUM_LIT:12><EOL>dy = self.ptc.daysInMonth(mth, yr)<EOL>sourceTime = (yr, mth, dy, startHour, startMinute,<EOL>startSecond, wd, yd, isdst)<EOL>ctx.updateAccuracy(ctx.ACU_MONTH)<EOL><DEDENT>elif self.ptc.CRE_WEEKDAY.match(unit):<EOL><INDENT>m = self.ptc.CRE_WEEKDAY.match(unit)<EOL>debug and log.debug('<STR_LIT>')<EOL>wkdy = m.group()<EOL>if modifier == '<STR_LIT>':<EOL><INDENT>ctx.updateAccuracy(ctx.ACU_HOUR)<EOL>sourceTime, subctx = self.parse(wkdy, sourceTime,<EOL>VERSION_CONTEXT_STYLE)<EOL>sTime = self.ptc.getSource(modifier, sourceTime)<EOL>if sTime is not None:<EOL><INDENT>sourceTime = sTime<EOL>ctx.updateAccuracy(ctx.ACU_HALFDAY)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>dowOffset = offset<EOL>relativeModifier = modifier not in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>if relativeModifier:<EOL><INDENT>dowOffset = <NUM_LIT:0><EOL><DEDENT>wkdy = self.ptc.WeekdayOffsets[wkdy]<EOL>diff = self._CalculateDOWDelta(<EOL>wd, wkdy, dowOffset, self.ptc.DOWParseStyle,<EOL>self.ptc.CurrentDOWParseStyle)<EOL>start = datetime.datetime(yr, mth, dy, startHour,<EOL>startMinute, startSecond)<EOL>target = start + datetime.timedelta(days=diff)<EOL>if chunk1 != '<STR_LIT>' and relativeModifier:<EOL><INDENT>t, subctx = self.parse(chunk1, sourceTime, VERSION_CONTEXT_STYLE)<EOL>if subctx.hasDateOrTime:<EOL><INDENT>delta = time.mktime(t) - time.mktime(sourceTime)<EOL>target = start + datetime.timedelta(days=diff) + datetime.timedelta(seconds=delta * offset)<EOL>chunk1 = '<STR_LIT>'<EOL><DEDENT><DEDENT>sourceTime = target.timetuple()<EOL><DEDENT>ctx.updateAccuracy(ctx.ACU_DAY)<EOL><DEDENT>elif chunk1 == '<STR_LIT>' and chunk2 == '<STR_LIT>' and self.ptc.CRE_TIME.match(unit):<EOL><INDENT>m = self.ptc.CRE_TIME.match(unit)<EOL>debug and log.debug('<STR_LIT>')<EOL>(yr, mth, dy, hr, mn, sec, wd, yd, isdst), subctx =self.parse(unit, None, VERSION_CONTEXT_STYLE)<EOL>start = datetime.datetime(yr, mth, dy, hr, mn, sec)<EOL>target = start + datetime.timedelta(days=offset)<EOL>sourceTime = target.timetuple()<EOL><DEDENT>else:<EOL><INDENT>debug and log.debug('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>chunk1, unit)<EOL>unit = unit.strip()<EOL>if unit:<EOL><INDENT>s = '<STR_LIT>' % (unit, chunk2)<EOL>t, subctx = self.parse(s, sourceTime, VERSION_CONTEXT_STYLE)<EOL>if subctx.hasDate:  <EOL><INDENT>u = unit.lower()<EOL>if u in self.ptc.Months oru in self.ptc.shortMonths:<EOL><INDENT>yr, mth, dy, hr, mn, sec, wd, yd, isdst = t<EOL>start = datetime.datetime(<EOL>yr, mth, dy, hr, mn, sec)<EOL>t = self.inc(start, year=offset).timetuple()<EOL><DEDENT>elif u in self.ptc.Weekdays:<EOL><INDENT>t = t + datetime.timedelta(weeks=offset)<EOL><DEDENT><DEDENT>if subctx.hasDateOrTime:<EOL><INDENT>sourceTime = t<EOL>chunk2 = '<STR_LIT>'<EOL><DEDENT><DEDENT>chunk1 = chunk1.strip()<EOL>if chunk1:<EOL><INDENT>try:<EOL><INDENT>m = list(self.ptc.CRE_NUMBER.finditer(chunk1))[-<NUM_LIT:1>]<EOL><DEDENT>except IndexError:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>qty = None<EOL>debug and log.debug('<STR_LIT>')<EOL>qty = self._quantityToReal(m.group()) * offset<EOL>chunk1 = '<STR_LIT>' % (chunk1[:m.start()],<EOL>qty, chunk1[m.end():])<EOL><DEDENT>t, subctx = self.parse(chunk1, sourceTime,<EOL>VERSION_CONTEXT_STYLE)<EOL>chunk1 = '<STR_LIT>'<EOL>if subctx.hasDateOrTime:<EOL><INDENT>sourceTime = t<EOL><DEDENT><DEDENT>debug and log.debug('<STR_LIT>', modifier)<EOL>sTime = self.ptc.getSource(modifier, sourceTime)<EOL>if sTime is not None:<EOL><INDENT>debug and log.debug('<STR_LIT>')<EOL>sourceTime = sTime<EOL>ctx.updateAccuracy(ctx.ACU_HALFDAY)<EOL><DEDENT><DEDENT>debug and log.debug('<STR_LIT>',<EOL>chunk1, chunk2, sourceTime)<EOL>return '<STR_LIT>' % (chunk1, chunk2), sourceTime<EOL>
Evaluate the C{modifier} string and following text (passed in
as C{chunk1} and C{chunk2}) and if they match any known modifiers
calculate the delta and apply it to C{sourceTime}.

@type  modifier:   string
@param modifier:   modifier text to apply to sourceTime
@type  chunk1:     string
@param chunk1:     text chunk that preceded modifier (if any)
@type  chunk2:     string
@param chunk2:     text chunk that followed modifier (if any)
@type  sourceTime: struct_time
@param sourceTime: C{struct_time} value to use as the base

@rtype:  tuple
@return: tuple of: remaining text and the modified sourceTime