Skip to main content

Generate a random date from range given.

Project description

Package

radar

Description

Random date generation.

Installation

Install latest stable version from pypi:

$ pip install radar

Optionally install python-dateutil (see Usage and examples section first).

$ pip install python-dateutil

Usage and examples

If you expect to have really weird date formats when generating random dates from strings, you might want to consider installing wonderful python-dateutil package.

A basic (fallback) parser (radar.utils.parse) is used when dateutil is not available.

When generating thousands of objects (using dateutil or fallback parser), you’re advised to pass datetime.datetime or datetime.date objects to radar, rather than passing str (performance issue).

In numbers (based on my local tests), using dateutil could slow down things 35 times. Basic built-in parser slows down things 10 times compared to when passing datetime.datetime or datetime.date objects directly.

Generate random date

>>> import radar
>>> radar.random_date(start='2013-05-24', stop='2013-07-01')
datetime.date(2013, 5, 31)

Generate random datetime

>>> radar.random_datetime(start='2013-05-24T00:00:00', stop='2013-05-24T23:59:59')
datetime.datetime(2013, 5, 24, 16, 54, 52)
>>> start = radar.utils.parse('2012-01-01')
datetime.datetime(2012, 1, 1, 0, 0)
>>> stop = radar.utils.parse('2013-01-01')
datetime.datetime(2013, 1, 1, 0, 0)
>>> radar.random_datetime(start=start, stop=stop)
datetime.datetime(2012, 6, 19, 13, 48, 7)
>>> radar.random_datetime(start=start)
datetime.datetime(2012, 2, 26, 6, 49, 7)
>>> radar.random_datetime(stop=stop)
datetime.datetime(1985, 12, 10, 2, 40, 50)

Generate random time

>>> radar.random_time(start='2012-01-01T00:00:00', stop='2012-01-01T23:59:59')
datetime.time(11, 33, 59)

License

GPL 2.0/LGPL 2.1

Support

For any issues contact me at the e-mail given in the Author section.

Author

Artur Barseghyan <artur.barseghyan@gmail.com>

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

radar-0.1.tar.gz (2.5 kB view hashes)

Uploaded Source

Supported by

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