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 details)

Uploaded Source

File details

Details for the file radar-0.1.tar.gz.

File metadata

  • Download URL: radar-0.1.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for radar-0.1.tar.gz
Algorithm Hash digest
SHA256 0eaf3ae0f563e3979186a7cb543dac347af8f0087181edc15e1b02ad53d8f56b
MD5 f76ee87c5de1f094e9cc9114e7175b5a
BLAKE2b-256 e9eff3b99b565eb039c75a2bc84158c5d07ee2d3114467679544fb70f0839423

See more details on using hashes here.

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