Calc3 - Styxling/Feather GitHub Wiki

The Calc3 module converts time between numeric values (seconds) and human-friendly strings. It supports both basic and extended time formats.

What It Does

  • Number to String:
    Converts a time in seconds (including decimals) into a readable format like 1:05:30 or 1:05:30.25.

  • String to Number:
    Converts a formatted time string (e.g., 1:05:30) back into seconds.

  • Extended Format:
    Provides a detailed description of the time, breaking it down into weeks, days, hours, minutes, and seconds.

Main Functions

  • calculateTimeUnits(abs)
    Breaks a total number of seconds into weeks, days, hours, minutes, and seconds.

  • constructTimeString(hour, minute, second, decimal, DecimalMaxPlaces)
    Creates a basic time string (e.g., 1:05:30), optionally including decimals.

  • extendedTimeString(week, day, hour, minute, second, decimal)
    Builds an extended string, for example:
    1 week, 2 days, 3 hours, 4 minutes, 5.1234 seconds.

  • numberToString(Time, Overtime, DecimalMaxPlaces, ForceHour)
    Converts a numeric time value into both a simple formatted string and an extended descriptive string.

  • stringToNumber(Time)
    Converts a time string back into a numerical value in seconds.

  • con(Time, Overtime, DecimalMaxPlaces, ForceHour)
    A helper function that checks if the input is a number or a string and then performs the appropriate conversion.

Usage Example

local Directory = require(ServerStorage.Directory.MainModule)
local Calc3 = Directory("_replicated", "Calc3")

-- Example: Converting seconds to formatted time strings
local basicStr, extendedStr = Calc3.con(3661.75, true, 2, true)
print("Basic Time:", basicStr)       -- e.g., "1:01:01.75"
print("Extended Time:", extendedStr) -- e.g., "0 week, 0 day, 1 hour, 1 minute, 1.75 seconds"

-- Example: Converting a time string back to seconds
local timeInSeconds = Calc3.con("1:01:01")
print("Time in Seconds:", timeInSeconds)  -- e.g., 3661