'Update the date/time format for this parser, and generate
the corresponding pyparsing grammar
@param dtfmt: the date/time format'

def set_format(self, dtfmt):

    if (not isinstance(dtfmt, basestring)):
        raise TypeError(('Invalid    date/time    format:    %s    (%s)' % (dtfmt, type(dtfmt))))
    import pyparsing as pp
    self.ParseException = pp.ParseException
    from s3utils import s3_unicode
    rules = self.rules
    if (rules is None):
        rules = self.rules = self._get_rules()
    result = []
    sequence = []
    def close(s):
        s = ''.join(s).strip()
        if s:
            result.append(pp.Suppress(pp.Literal(s)))
    rule = False
    for c in s3_unicode(dtfmt):
        if (rule and (c in rules)):
            sequence.pop()
            close(sequence)
            result.append(rules[c])
            sequence = []
            rule = False
            continue
        if ((c == '%') and (not rule)):
            rule = True
        else:
            rule = False
        sequence.append(c)
    if sequence:
        close(sequence)
    if result:
        grammar = result[0]
        for item in result[1:]:
            grammar += item
    else:
        grammar = pp.Suppress(pp.Regex('.*'))
    self.grammar = grammar
    return grammar
