Skip to main content

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 Python versions PyPI - Implementation Wheel Downloads Version
Tests codecov Unit tests Ruff Deploy to PyPI
Activity GitHub contributors Last commit GitHub all releases GitHub issues GitHub closed issues GitHub pull requests GitHub closed pull requests
QA CodeFactor Rating
Other License FOSSA Status Known Vulnerabilities Repository size Code size Lines of code

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?

  1. Fork this repository to your own GitHub account and then clone it to your local device
  2. Install poetry (if it isn't already installed)
  3. Run poetry install in the project directory. This fetches development dependencies like pytest 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.1.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

python_ms-1.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file python_ms-1.1.1.tar.gz.

File metadata

  • Download URL: python_ms-1.1.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for python_ms-1.1.1.tar.gz
Algorithm Hash digest
SHA256 70ab0087c89d33da08c3e95f72faac965968a6ef4189fe4f158f1df5c0d8400d
MD5 73346bb6af9ee13b1a0ab5e72c755d1c
BLAKE2b-256 18c3df826eb3438d0fdd87e4b6569c6c0a177c6b60f96462d572ac254d63da0d

See more details on using hashes here.

File details

Details for the file python_ms-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: python_ms-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for python_ms-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb25fd90dd5ed38d674fcfc455ed8e3141db835fb915d2f01c584e4ce1a0fbb4
MD5 d7c6e785e7f43070fa9b8ccac9677413
BLAKE2b-256 a9e52b5092e75502ce71aa110e03acf2cbaecdebdac3341271251f0460911d0d

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