Skip to content

Time

Time and date helpers for localized timestamps, elapsed-time text, and duration formatting.


Overview

The time library centralizes shared time formatting under `lia.time`. It converts timestamps and formatted date strings into localized readable output, builds current date and hour strings using the configured timestamp style, and formats durations into day, hour, and minute components.

lia.time.timeSince(strTime)View Source

Purpose

Returns a localized string describing how much time has passed since a timestamp or parsed date string.

Realm

Shared

Parameters

number|string strTime A Unix timestamp, or a date string supported by `lia.time.ParseTime`.

Returns

string A localized elapsed-time string, or a localized invalid input or invalid date message.

Example Usage

  print(lia.time.timeSince(os.time() - 3600))
  print(lia.time.timeSince("2024-01-01"))

lia.time.toNumber(str)View Source

Purpose

Converts a formatted timestamp string into a table of numeric date and time components.

Realm

Shared

Parameters

string str optional A timestamp string formatted as `YYYY-MM-DD HH:MM:SS`. Defaults to the current local time when nil.

Returns

table A table containing `year`, `month`, `day`, `hour`, `min`, and `sec` numeric fields.

Example Usage

  local date = lia.time.toNumber("2024-01-31 18:45:10")
  print(date.year, date.month, date.day)

lia.time.getDate()View Source

Purpose

Returns the current localized date and time string using the configured timestamp format.

Realm

Shared

Returns

string The current date and time using either the American or default timestamp style.

Example Usage

  print(lia.time.getDate())

lia.time.formatDHM(seconds)View Source

Purpose

Formats a duration in seconds as localized days, hours, and minutes.

Realm

Shared

Parameters

number seconds optional The duration in seconds. Nil and negative values are treated as zero.

Returns

string A localized duration string containing the calculated days, hours, and minutes.

Example Usage

  print(lia.time.formatDHM(93780))

lia.time.getHour()View Source

Purpose

Returns the current hour using the configured timestamp format.

Realm

Shared

Returns

number|string The current 24-hour value when American timestamps are disabled, or a localized 12-hour string with an AM/PM suffix when enabled.

Example Usage

  print(lia.time.getHour())