Time package supporting chain call
Project description
py-itime is a time package supporting chain call.
install and use:
pip install py-itime from itime import iTime
Example
# get time str of previous day with specified hours >>> iTime(f'{iTime.now().delta(days=-1).date_str()} 10:00:00').time_str() '2021-07-20 10:00:00' # get unix timestamp of previous day >>> iTime.now().delta(days=-1).uts(is_ms=True) 1627211818635 # get corresponding unix timestamp with specified time str >>> iTime('2021-07-20 10:00:00').uts() 1626746400 # get time str of UTC time which is converted and down sampled by local time >>> iTime.now().delta(hours=-8).ds(minutes=5).time_str() '2021-08-02 08:20:00'
Initialize
There are 4 ways to initialize an iTime object.
# 1. init with time str, format '%Y{}%m{}%d', '%Y{}%m{}%d %H:%M:%S' delimiter could be '','-','/'. >>> iTime('20210701') >>> iTime('2021-07-01 00:00:01') >>> iTime('2021/07/01 00:00:01') # 2. init with unix timestamp, support second and milliseconds, default as second >>> iTime(1625068800) >>> iTime(1625068800000, is_ms=True) # if is milliseconds, is_ms=True >>> iTime(1625068800.123) # float is also supported # 3. init with custom time str, use iTime.strp(time: str, fmt: str) >>> iTime('2021-07-01 12:05', fmt='%Y-%m-%d %H:%M') # 4. init datetime.datetime instance >>> dt = datetime.datetime.now() >>> iTime(dt)
class iTime
- iTime.now() -> iTime
get current local time.
- iTime.today() -> iTime
get current date, hour minute second is 00:00:00.
- iTime.strp(time: str, fmt: str) -> iTime
init iTime from custom time str format.
- iTime.uts(is_ms=False) -> int
get unix timestamp, if is_ms=True, get milliseconds.
- iTime.date_str(deli=’-’) -> str
get date str, deli is delimiter include ‘’, ‘-’, ‘/’.
- time_str(deli=’-’) -> str
get time str, deli is delimiter include ‘’, ‘-’, ‘/’.
- strf(fmt) -> str
get custom time str with given fmt.
- pop() -> datetime.datetime
get datetime.datetime object from iTime instance
- delta(days=0, seconds=0, minutes=0, hours=0) -> iTime
get offset time.
- ds(hours=None, minutes=None, seconds=None) -> iTime
down sample time, example as follows.
>>> it = iTime('2021-07-21 23:23:12') >>> it.ds(hours=5) '2021-07-21 20:00:00' >>> it.ds(hours=23) '2021-07-21 23:00:00' >>> it.ds(minutes=5) '2021-07-21 23:20:00' >>> it.ds(seconds=t) '2021-07-21 23:23:10'
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
Built Distribution
File details
Details for the file py-itime-0.0.2.tar.gz
.
File metadata
- Download URL: py-itime-0.0.2.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4f8dcff4836bfc07ae7de0bee91b82f8b82eefd346af06d21d59f6ca16d1070 |
|
MD5 | b54e4b38415c78197eef91a13a90010f |
|
BLAKE2b-256 | 24b2864c22d44e422b43e3d013165bf746c9b046cf47c9bf4d87001b7c1db109 |
File details
Details for the file py_itime-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: py_itime-0.0.2-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 187eae502ad690bdf54c7ca67b814f71a6a844355b29c13804d47ba3185adc5d |
|
MD5 | 94cc0f2cc8bb5edba4d4051b15f31fa6 |
|
BLAKE2b-256 | 4902d3a233d3fedf088dab45c1875094a9d0fb76323288b92ab02abd4a05af4c |