Skip to content

Commit

Permalink
fix: handle microsecond range error, closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteBaker committed Nov 5, 2021
1 parent 48242f4 commit cdff06f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/randomtimestamp?label=Python) ![PyPI - License](https://img.shields.io/pypi/l/randomtimestamp?label=License&color=red) ![Maintenance](https://img.shields.io/maintenance/yes/2022?label=Maintained) ![PyPI](https://img.shields.io/pypi/v/randomtimestamp?label=PyPi) ![PyPI - Status](https://img.shields.io/pypi/status/randomtimestamp?label=Status) ![PyPI - Format](https://img.shields.io/pypi/format/randomtimestamp?label=Format) ![PyPI - Downloads](https://img.shields.io/pypi/dm/randomtimestamp?label=Downloads&color=yellow)

# randomtimestamp <sup> (v2.1)</sup>
# randomtimestamp <sup> (v2.2)</sup>
Random timestamp generator
## Installation
You know it:
Expand All @@ -19,13 +19,12 @@ To use the script from command line

#### Python Module Usage

In v2.1, the functions **randomtimestamp**, **random_time**, and **random_date** are available.
In v2.2, the functions **randomtimestamp**, **random_time**, and **random_date** are available.

1. **randomtimestamp()** takes six optional arguments. A call without arguments returns a datetime between **January 1st, 1950, 00:00:00** and **({today}, 23:59:59)**.

**NOTE**: **start/end** are resolved before **start_year/end_year**, therefore **start_year/end_year** have no effect if **start/end** have been provided.

**WARNING [breaking changes]** ⚠️ : Order of arguments to **randomtimestamp** has been changed in v2.1. If you're passing parameters as positionals, be careful before upgrading. The function also returns a *datetime* object rather than a string.
**WARNING [breaking changes]** : Order of arguments to **randomtimestamp** has been changed in v2.1. If you're passing parameters as positionals, be careful before upgrading. The function also returns a *datetime* object rather than a string.
```
randomtimestamp(
start_year: int = 1950,
Expand Down Expand Up @@ -62,6 +61,8 @@ In any of these function calls, **start < end** & **start_year < end_year** is m

## Changelog:

##### v2.2
- Fixed microsecond handling bug in datetime range. Closes [issue](https://github.com/ByteBaker/ubuntu21-btfix/issues/1).
##### v2.1
- Dropped a minor version identifier to account for the small size of module. Only 2 digits to be used hereafter.
- [Breaking change] Order of arguments to randomtimestamp() changed. Code using older versions without keyword arguments breaks.
Expand Down
4 changes: 2 additions & 2 deletions randomtimestamp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def validate(
raise ValueError(error)
else:
# both 'start' & 'end' are valid
start_datetime, end_datetime = start, end
start_datetime, end_datetime = start.replace(microsecond=0), end.replace(microsecond=0)
else:
# 'end' is not a valid datetime object
# raise TypeError
error = "'end' must be an instance of datetime"
raise TypeError(error)
else:
# 'end' not given, use now() as default
start_datetime = start
start_datetime = start.replace(microsecond=0)
end_datetime = datetime.combine(MAX_DATE, time(23, 59, 59))
if start_datetime > end_datetime:
# 'start' < now() required
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# This call to setup() does all the work
setup(
name="randomtimestamp",
version="2.1",
version="2.2",
description="Generate random time stamps",
long_description=README,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit cdff06f

Please sign in to comment.