A Python equivalent to the JavaScript ms package.
Project description
Python-ms
A Python equivalent to the JavaScript ms
package.
This port of the original project supports some additional string-to-ms conversions, but otherwise the functionality is identical. This version also uses integers for everything to avoid rounding errors with floating-point numbers when using large values.
Using the project's unit tests as examples is recommended, as they cover everything.
Type | Badges |
---|---|
PyPI | |
Tests | |
Activity | |
QA | |
Other |
Installation
The project is available via PyPI:
pip install python_ms
Examples
Convert from strings
import python_ms as ms
ms('2 days') # 172_800_000
ms('1d') # 86_400_000
ms('10h') # 36_000_000
ms('2.5 hrs') # 9_000_000
ms('2h') # 7_200_000
ms('1m') # 60_000
ms('5s') # 5_000
ms('1y') # 31_557_600_000
ms('100') # 100
ms('-3 days') # -259_200_000
ms('-1h') # -3_600_000
ms('-200') # -200
Convert from milliseconds
import python_ms as ms
ms(60_000) # "1m"
ms(2 * 60_000) # "2m"
ms(-3 * 60_000) # "-3m"
ms(ms('10 hours')) # "10h"
Time format written out
import python_ms as ms
ms(60_000, long=True) # "1 minute"
ms(2 * 60_000, long=True) # "2 minutes"
ms(-3 * 60_000, long=True) # "-3 minutes"
ms(ms('10 hours'), long=True) # "10 hours"
Features
- Has no dependencies aside from the standard library
- If a number is supplied to
python_ms
, a string with a unit is returned - If a string that contains the number is supplied, it returns it as a number (e.g.: it returns
100
for'100'
) - If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
Related Packages
- ms - The original JavaScript
ms
package
Caught a Bug?
- Fork this repository to your own GitHub account and then clone it to your local device
- Install
poetry
(if it isn't alreeady installed) - Run
poetry install
in the project directory. This fetches development dependencies likepytest
and sets up everything for you to start debugging
As always, you can run the tests using: poetry run pytest
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
python_ms-1.0.2.tar.gz
(8.1 kB
view details)
Built Distribution
File details
Details for the file python_ms-1.0.2.tar.gz
.
File metadata
- Download URL: python_ms-1.0.2.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.0 Linux/5.15.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 867639e42b593aa24ec6080f0d52fc91ccd81081f5bde3da1ec28b81b0548f2f |
|
MD5 | e228e064bd5717483360666c98d9dea9 |
|
BLAKE2b-256 | 9ce28b40e1fe93a253108d93ad09b099bab88bba0f082cd7351a4488251ebaea |
File details
Details for the file python_ms-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: python_ms-1.0.2-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.0 Linux/5.15.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a973081ff589cc30ab174c0ece5329af71e67f66ec9d9a50e5c7e12340371040 |
|
MD5 | a473e6505b38686a79778f3cddf15756 |
|
BLAKE2b-256 | aa34c49f734f10872d62a43a2b3fffaa5706e01dd07020b604a67148258a7ce6 |