Skip to main content
https://travis-ci.org/petedmarsh/dtargs.png?branch=master

Introduction

dtargs is a small module that makes accepting date/time arguments with Argparse easier.

Examples

A date argument

import argparse
import dtargs

parser = argparse.ArgumentParser()
parser.add_argument('start', type=dtargs.DateType()) # defaults to %Y-%m-%d
parser.add_argument('end', type=dtargs.DateType('%d/%m/%Y'))

A date/time argument

import argparse
import dtargs

parser = argparse.ArgumentParser()
parser.add_argument('start', type=dtargs.DateTimeType()) # defaults to %Y-%m-%dT%H:%M:%SZ
parser.add_argument('end', type=dtargs.DateTimeType('%H:%M:%S_%Y-%m-%d', tz=None)

Timezones

The DateTimeType accepts a tz parameter, which is handled thusly

import dtargs

dtargs.DateTimeType()('2015-01-02T12:34:56Z')
>>> datetime.datetime(2015, 1, 2, 12, 34, 56, tzinfo=<UTC>)

dtargs.DateTimeType(tz=None)('2015-01-02T12:34:56Z')
>> datetime.datetime(2015, 1, 2, 12, 34, 56, tzinfo=None)

dtargs.DateTimeType('%Y-%m-%dT%H:%M:%S%z', tz=None)('2015-01-02T12:34:56+0100')
>> datetime.datetime(2015, 1, 2, 12, 34, 56, tzinfo=datetime.timezone(datetime.timedelta(0, 3600))

dtargs.DateTimeType('%Y-%m-%dT%H:%M:%S%z', tz=pytz.utc)('2015-01-02T12:34:56+0500')
>> datetime.datetime(2015, 1, 2, 7, 34, 56, tzinfo=<UTC>)

Testing

Install dependencies

$ pip install -r dev-requirements.txt

To run tests

$ py.test

Release files for dtargs 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for dtargs 1.0.0
File Interpreter ABI Platform
dtargs-1.0.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / dtargs-1.0.0-py2.py3-none-any.whl

Download URL dtargs-1.0.0-py2.py3-none-any.whl
Size 4.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0a66565f48e6ee35cd6032b1dc1132d773e0b36c8ac92d3bb83eb912edbec5ce
BLAKE2b-256 checksum
How to use checksums
f4852802d28f0efd8c7f9ec04fd82c1d2e9fcb9e02429e03fe86e263b507002e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page