lia.time

Various useful helper functions.

Functions

CurrentLocalTime()

Returns the current local time in "HH:MM:SS - DD/MM/YYYY" format.

Returns

  • string

    The current local time string.

DaysBetween(strTime1, strTime2)

Calculates the number of days between two dates (ignoring time of day).

Parameters

  • strTime1 String

    A time string "HH:MM:SS - DD/MM/YYYY"

  • strTime2 String

    A time string "HH:MM:SS - DD/MM/YYYY"

Returns

  • number or nil

    The number of days between the two dates, or a string error message.

FormatTimestamp(timestamp)

Formats a UNIX timestamp into "HH:MM:SS - DD/MM/YYYY".

Parameters

  • timestamp Integer

    A UNIX timestamp.

Returns

  • string

    The formatted time string.

GetFormattedDate(StartingMessage, includeWeekDay, includeDay, includeMonth, includeYear, includeTime)

Generates a formatted date string based on the current system time.

Parameters

  • StartingMessage String optional

    A message to prepend to the formatted date.

  • includeWeekDay Boolean optional

    Whether to include the day of the week in the formatted date.

  • includeDay Boolean optional

    Whether to include the day of the month in the formatted date.

  • includeMonth Boolean optional

    Whether to include the month in the formatted date.

  • includeYear Boolean optional

    Whether to include the year in the formatted date.

  • includeTime Boolean optional

    Whether to include the time in the formatted date.

Returns

  • any

    string The formatted date string.

GetFormattedDateInGame(StartingMessage, includeWeekDay, includeDay, includeMonth, includeYear, includeTime)

Generates a formatted date string based on the current system time for in-game usage.

Parameters

  • StartingMessage String optional

    A message to prepend to the formatted date.

  • includeWeekDay Boolean optional

    Whether to include the day of the week in the formatted date.

  • includeDay Boolean optional

    Whether to include the day of the month in the formatted date.

  • includeMonth Boolean optional

    Whether to include the month in the formatted date.

  • includeYear Boolean optional

    Whether to include the year in the formatted date.

  • includeTime Boolean optional

    Whether to include the time in the formatted date.

Returns

  • any

    string The formatted date string.

GetPreFormattedDate(StartingMessage, timeToFormat, includeWeekDay, includeDay, includeMonth, includeYear, includeTime)

Generates a pre-formatted date string based on the provided time.

Parameters

  • StartingMessage String optional

    A message to prepend to the formatted date.

  • timeToFormat Table

    The time to format.

  • includeWeekDay Boolean optional

    Whether to include the day of the week in the formatted date.

  • includeDay Boolean optional

    Whether to include the day of the month in the formatted date.

  • includeMonth Boolean optional

    Whether to include the month in the formatted date.

  • includeYear Boolean optional

    Whether to include the year in the formatted date.

  • includeTime Boolean optional

    Whether to include the time in the formatted date.

Returns

  • any

    string The formatted date string.

GetPreFormattedDateInGame(StartingMessage, timeToFormat, includeWeekDay, includeDay, includeMonth, includeYear, includeTime)

Generates a pre-formatted date string based on the provided time for in-game usage.

Parameters

  • StartingMessage String optional

    A message to prepend to the formatted date.

  • timeToFormat Table

    The time to format.

  • includeWeekDay Boolean optional

    Whether to include the day of the week in the formatted date.

  • includeDay Boolean optional

    Whether to include the day of the month in the formatted date.

  • includeMonth Boolean optional

    Whether to include the month in the formatted date.

  • includeYear Boolean optional

    Whether to include the year in the formatted date.

  • includeTime Boolean optional

    Whether to include the time in the formatted date.

Returns

  • any

    string The formatted date string.

HMSToSeconds(hour, minute, second)

Converts hours, minutes, and seconds into a total number of seconds.

Parameters

  • hour Integer

    The hour component.

  • minute Integer

    The minute component.

  • second Integer

    The second component.

Returns

  • number

    The total number of seconds.

ParseTime(strTime)

Parses a time string ("HH:MM:SS - DD/MM/YYYY") into numeric components.

Parameters

  • strTime String

    The time string.

Returns

  • number

    year The parsed year

  • number

    month The parsed month

  • number

    day The parsed day

  • number

    hour The parsed hour

  • number

    minute The parsed minute

  • number

    second The parsed second

  • OR
  • nil

    If parsing fails

SecondsToDHMS(seconds)

Converts a number of seconds into days, hours, minutes, and seconds.

Parameters

  • seconds Integer

    The total number of seconds.

Returns

  • number

    Days

  • number

    Hours

  • number

    Minutes

  • number

    Seconds

TimeDifference(strTime)

Calculates the time difference in days between the given date and the current date.

Parameters

  • strTime String

    A time string in the format "HH:MM:SS - DD/MM/YYYY".

Returns

  • number or nil

    The difference in days between the given date and the current date, or nil if the input is invalid.

TimeSince(strTime)

Returns the amount of time passed since the given time. Expected format of strTime: "HH:MM:SS - DD/MM/YYYY"

Parameters

  • strTime String

    A time string in the specified format.

Returns

  • string

    A human-readable string indicating years, months, days, hours, minutes, and seconds passed.

TimeUntil(strTime)

Returns the amount of time until the given time. Expected format of strTime: "HH:MM:SS - DD/MM/YYYY"

Parameters

  • strTime String

    A time string in the specified format.

Returns

  • string

    A human-readable string indicating years, months, days, hours, minutes, and seconds remaining.

WeekdayName(strTime)

Returns the name of the weekday for the given date/time.

Parameters

  • strTime String

    A time string "HH:MM:SS - DD/MM/YYYY"

Returns

  • string

    The weekday name, or "Invalid date" if invalid.

toNumber(str)

Converts a date string to a table containing date and time components.

Parameters

  • str String

    The date string in the format "YYYY-MM-DD HH:MM:SS"

Returns

  • table

    Table containing date and time components