Skip to content

Commit 37b9329

Browse files
committed
v2.0.0 release ready
1 parent ef53c5d commit 37b9329

2 files changed

Lines changed: 76 additions & 27 deletions

File tree

README.md

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,95 @@
1-
# randomtimestamp
2-
Random timestamp generator
1+
![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 - Format](https://img.shields.io/pypi/format/randomtimestamp?label=Format) ![PyPI - Downloads](https://img.shields.io/pypi/dm/randomtimestamp?label=Downloads&color=yellow)
32

3+
# randomtimestamp <sup> (v2.0.0)</sup>
4+
Random timestamp generator
5+
## Installation
6+
You know it:
7+
```
8+
pip install randomtimestamp
9+
```
410
## Usage
5-
randomtimestamp can be used from the command line or imported as a python package.
11+
randomtimestamp can be used from the command line or imported as a python module.
612

7-
### Command line usage
13+
#### Command line usage
814
To use the script from command line
915
```
1016
$randomtimestamp
1117
30-08-1995 17:58:14
1218
```
1319

14-
### Python Package Usage
20+
#### Python Module Usage
1521

16-
The function **randomtimestamp** takes two optional arguments:
22+
In v2.0.0, the function **randomtimestamp** takes six optional arguments:
1723
```
18-
randomtimestamp(start_year=1950,text=True)
24+
randomtimestamp(
25+
start_year: int = 1950,
26+
text: bool = True,
27+
end_year: int = None,
28+
start: datetime.datetime = None,
29+
end: datetime.datetime = None,
30+
pattern: str = "%d-%m-%Y %H:%M:%S"
31+
)
1932
```
33+
Order of **start_year** & **text** hasn't been changed in v2.0.0 for backward compatibility. Future versions may not support the same order of arguments.
34+
35+
*Order of resolution:*
36+
1. start/end
37+
2. start_year/end_year
38+
39+
This means providing *start_year/end_year* to function call has no effect if *start/end* are also provided.
40+
2041
The default values of **start_year** and **text** are *1950* and *True* respectively.
21-
The timestamp is generated between *1950* and current year (*datetime.now().year*). Although a year before 1950 could have been used, but it didn't seem to be necessary.
42+
The timestamp is generated between *January 1st, 1950, 00:00:00* and *datetime.now()*.
43+
44+
45+
## Features:
46+
1. Call without arguments returns a random timestamp as string (**DD-MM-YYYY HH:MM:SS**), where **HH** follows 24-hour format. Setting **text=False** returns a *datetime* object.
47+
2. Lower limit of **start_year = 1950** has been removed. Now 1 <= start_year <= 9999 is allowed. **end_year** has been added to provide upper limit of timestamp beyond current year (within 1-9999). If **end_year** is not given, current year is used as **end_year**.
48+
49+
**NOTE**: Both are integers and *start_year <= end_year* is required. If *end_year* is provided, *start_year* is required too.
50+
51+
3. **start** and **end** arguments are datetime objects and can be used for more precise control over timestamp range. **start_year** & **end_year** have no effect if **start** and **end** are given. If **end** is not given, **datetime.now()** is used as **end**.
52+
53+
**NOTE**: Both are datetime objects and *start < end* is required. If *end* is provided, *start* is required too.
54+
55+
4. **pattern** can be used to generate timestamps in desired format, using valid formats described in [datetime documentation](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes). The default pattern is **"%d-%m-%Y %H:%M:%S"**.
56+
57+
**NOTE**: *pattern* has no effect if **text=False**.
2258

23-
By default, the function returns the output as string in format (**DD-MM-YYYY HH:MM:SS**), where **HH** is in 24-hour format. Setting **text=False** returns a *datetime* object.
2459

25-
Here are examples of all the possible syntaxes:
60+
61+
## Examples:
62+
Here are some examples of the possible syntaxes:
2663
```
27-
>>>from randomtimestamp import randomtimestamp
28-
29-
>>>randomtimestamp()
64+
>>> from randomtimestamp import randomtimestamp
65+
66+
>>> randomtimestamp()
3067
'02-06-1970 23:34:10'
68+
69+
>>> randomtimestamp(start_year=2020, end_year=2021)
70+
'05-09-2021 17:24:28'
71+
72+
>>> randomtimestamp(start_year=2020, end_year=2021, text=False)
73+
datetime.datetime(2021, 1, 10, 5, 6, 19)
74+
75+
>>> from datetime import datetime
76+
>>> start = datetime(2020, 5, 10, 0, 0, 0)
77+
>>> end = datetime(2020, 10, 10, 0, 0, 0)
78+
>>> randomtimestamp(start=start, end=end)
79+
'27-09-2020 20:42:55'
3180
32-
>>>randomtimestamp(2010)
33-
'02-06-2013 23:34:10'
34-
35-
>>>randomtimestamp(start_year=2005)
36-
'10-04-2015 10:55:02'
37-
38-
>>>randomtimestamp(2010,False)
39-
datetime.datetime(2010, 5, 16, 3, 32, 18)
40-
41-
>>>randomtimestamp(text=False)
42-
datetime.datetime(1951, 2, 13, 18, 19, 1)
81+
>>> randomtimestamp(start=start, end=end, pattern='%d-%h-%Y %I:%M:%S %p')
82+
'03-Aug-2020 08:06:27 PM'
4383
```
84+
In any case, if you ever feel stuck, use **help(randomtimestamp)** inside Python's REPL.
85+
86+
---
87+
88+
#### Footnote:
89+
Type validation has been done, but it won't be required for most developers. If you're someone who likes to break the code with deliberately crafted inputs, you'd most likely receive a **TypeError** or a **ValueError**.
90+
91+
However, if you do find a bug, please report to make the experience better for other developers.
92+
4493

4594
## License
4695
This project is released under [GNU GENERAL PUBLIC LICENSE V3](https://www.gnu.org/licenses/gpl-3.0.en.html).

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# This call to setup() does all the work
1111
setup(
1212
name="randomtimestamp",
13-
version="1.0.0",
13+
version="2.0.0",
1414
description="Generate random time stamps",
1515
long_description=README,
1616
long_description_content_type="text/markdown",
@@ -21,8 +21,8 @@
2121
classifiers=[
2222
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
2323
"Operating System :: OS Independent",
24-
"Programming Language :: Python :: 3",
2524
"Programming Language :: Python :: 3.7",
25+
"Development Status :: 5 - Production/Stable",
2626
],
2727
packages=["randomtimestamp"],
2828
include_package_data=True,
@@ -34,4 +34,4 @@
3434
"randomtimestamp=randomtimestamp.__main__:main",
3535
]
3636
},
37-
)
37+
)

0 commit comments

Comments
 (0)