A package that converts string times into milliseconds and milliseconds back to readable strings
Project description
String to Milliseconds Converter
This Python module provides functionality to convert between time strings and milliseconds, and vice versa.
Main Function
ms(time: str | int | float, decimal: bool = True) -> str | int | float
A versatile function that handles bidirectional conversion between time strings and milliseconds. Inspired by the ms npm package, it allows for both parsing time strings into milliseconds and converting milliseconds into human-readable time strings.
Parameters
time(str | int | float): The value to parse or convertdecimal(bool, optional): If False, returns string dates rounded to whole numbers. Default is True.
Functionality
String Input → Milliseconds Output:
- Parses time strings with format:
"<number> <unit>" - Supported units:
- Milliseconds:
ms,msec,msecs,milli,millis,msecond,mseconds - Minutes:
min,mins,m,minute,minutes - Hours:
h,hr,hrs,hour,hours - Weeks:
w,wk,wks,week,weeks - Years:
y,yr,yrs,year,years - Years will return as floats as they use the average weeks in a year (52.143 weeks).
Numeric Input → Human-readable String Output:
- Converts milliseconds to the most appropriate time unit
- Automatically handles pluralization
- Returns formatted strings like "2.5 Hours" or "1 Day"
Examples
ms("2.5 hours") # Returns 9000000
ms("3mins") # Returns 180000
ms(8280000) # Returns "2.3 Hours"
ms(8280000, decimal=False) # 2 Hours
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file string_to_ms-0.0.4.tar.gz.
File metadata
- Download URL: string_to_ms-0.0.4.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b94932bf455954402067cf8e108f53ac13b94f34ce3c4fa48c69c150cf94313
|
|
| MD5 |
0126cfb190a5f87cdacea1f029cd334e
|
|
| BLAKE2b-256 |
89737508c34aca801fd69eaa147e5dfdc81f520e63b5773e2307b2b3e23bdbc6
|
File details
Details for the file string_to_ms-0.0.4-py3-none-any.whl.
File metadata
- Download URL: string_to_ms-0.0.4-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c8c4d6f91ebcc1ffc5882dde1f24c5f3f6c41ac1a5169814d5c4936358b33ad
|
|
| MD5 |
1265d7ab91bf3d5e9b25183105f7c92e
|
|
| BLAKE2b-256 |
a51724d81e75396a5a1c2a0420319c0510ed611299521a1d79fdd15efcd80291
|