Exemplo n.º 1
0
 def __call__(self, parser, namespace, values, option_string=None):
     try:
         if type(values) == str:
             date = timeparser.parsedate(values)
         else:
             date = [timeparser.parsedate(d) for d in values]
     except ValueError:
         raise ArgumentError(self, self.ERR % (values, 'date'))
     else:
         setattr(namespace, self.dest, date)
Exemplo n.º 2
0
 def __call__(self, parser, namespace, values, option_string=None):
     value = ' '.join(values) if isinstance(values, list) else values
     try:
         date = timeparser.parsedate(value)
     except ValueError:
         raise ArgumentError(self, self.ERR % (values, 'date'))
     else:
         self.append(namespace, date)
Exemplo n.º 3
0
    def getdate(self, section, option):
        """
        Get option as datetime.date-instance.

        Args: section and option

        Which formats are accepted depens on the configuration of the
        timeparser-module. Feel free to change it.
        """
        return timeparser.parsedate(self.get(section, option))
Exemplo n.º 4
0
 def combine_datetime(self, datestring, timestring):
     date = timeparser.parsedate(datestring)
     time = timeparser.parsetime(timestring)
     return datetime.datetime.combine(date, time)
Exemplo n.º 5
0
 def test_type(self):
     self.assertIsInstance(timeparser.parsetime('23:44'), datetime.time)
     self.assertIsInstance(timeparser.parsedate('24.3.2013'), datetime.date)
     self.assertIsInstance(timeparser.parsedatetime('24.3.2013,23:44'), datetime.datetime)
     self.assertIsInstance(timeparser.parsetimedelta('24.3.2013,23:44'), datetime.timedelta)