Skip to main content

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 convert
  • decimal (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
  • Days: d, day, days
  • 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

https://github.com/chickenman34234/StringToMilliseconds

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

string_to_ms-0.0.5.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

string_to_ms-0.0.5-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file string_to_ms-0.0.5.tar.gz.

File metadata

  • Download URL: string_to_ms-0.0.5.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for string_to_ms-0.0.5.tar.gz
Algorithm Hash digest
SHA256 e3e73b9241284635452f6978435f5d5620c958a3d05e31063710d66ec31929fa
MD5 dac0e2e74c403c4d5354fdb43db746f8
BLAKE2b-256 6d7408622ac414b209ba45ddb4f98e2a0dfcb12b2f863542c8bbdfd14768ad0d

See more details on using hashes here.

File details

Details for the file string_to_ms-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: string_to_ms-0.0.5-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

Hashes for string_to_ms-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5417881203aa4a1bff7c1003af4873ae9390d59ca2104663f6e95e1e1b16080c
MD5 0dedaa5b9e0972cfe4540e63e18211e9
BLAKE2b-256 59c7373cb82f969ecc1260214b038b59383477b93932e97bfd346418eb645cea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page