Skip to main content

A python-module to parse strings to time-, date-, datetime- or timedelta-objects. Which formats are accepted is configurable. The module also provides classes to use with the argparse-module for parsing command-line arguments.

Project description

A python-module to parse strings to time-, date-, datetime- or timedelta-objects. Which formats are accepted is configurable. The module also provides classes to use with the argparse-module for parsing command-line arguments.

Latest Version

The latest version of this project can be found at : http://github.com/thomst/timeparser.

Installation

  • Option 1 : Install via pip

    pip install timeparser
  • Option 2 : If you have downloaded the source

    python setup.py install

Documentation

How to use?

>>> import timeparser
>>>
>>> timeparser.parsedate('24.4.13')
datetime.date(2013, 4, 24)
>>>
>>> timeparser.parsedate('24 Apr 2013')
datetime.date(2013, 4, 24)
>>>
>>> timeparser.parsetime('234405')
datetime.time(23, 44, 5)
>>>
>>> timeparser.TimeFormats.config(allow_no_sep=False)
>>> timeparser.parsetime('234405')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "timeparser.py", line 398, in parsetime
    raise ValueError("couldn't parse %s as time" % string)
ValueError: couldn't parse 234405 as time
>>>
>>> timeparser.parsedatetime('24-04-13_23:44:05')
datetime.datetime(2013, 4, 24, 23, 44, 5)

or with argparse

>>> import argparse
>>> from timeparser import ParseDatetime
>>>
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--datetime', action=ParseDatetime, nargs='+')
>>>
>>> parser.parse_args("--datetime 2.4.2013 23:02".split()).datetime
datetime.datetime(2013, 4, 2, 23, 2)

Reporting Bugs

Please report bugs at github issue tracker: https://github.com/thomst/timeparser/issues

Author

thomst <thomaslfuss@gmx.de> Thomas Leichtfuß

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timeparser-0.3.1.tar.gz (7.2 kB view details)

Uploaded Source

File details

Details for the file timeparser-0.3.1.tar.gz.

File metadata

  • Download URL: timeparser-0.3.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for timeparser-0.3.1.tar.gz
Algorithm Hash digest
SHA256 9c59da1c1a045a57151b12f04d8aa3e76bc1df43995d2632be2badabf188e04f
MD5 2b6c2763be4106a30fa97f374a7e6805
BLAKE2b-256 a188faa6da2e2e050a25c8176efab4a10e08bf9c4d81139a0a4d3c07f86121d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page