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
  • 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.3.tar.gz (7.5 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.3-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

Hashes for string_to_ms-0.0.3.tar.gz
Algorithm Hash digest
SHA256 98c1d8e07eff245703082192592534deafabd58c53911518038838222bb9a8f6
MD5 acbf931225f8a7d849d066be023e16ec
BLAKE2b-256 719782820da7bfd0f11beaa56dfc07ad9da4dc23183ca8146da8e3153783d4f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: string_to_ms-0.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 acaa300b61489f39c32a47e49d739e15ac6cb631d3b634d35d423b2720429eb2
MD5 31c9b1f4fd8f12c8969024a21287f574
BLAKE2b-256 63ee7d1ee6fadd86b1f68d1832563ae4bfd5544e16e2e625c4e287630464b1e7

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