Time Stamp module

Hello, Developers and all alike!

I created this TimeStamp Module that was originally just going to be a part of a public resource I’m working on. Here’s how you use it!

local timeStamp = require(TimeStamp)
local RightNow = DateTime.now()
local TextLabel = Instance.new("TextLabel")

local myCoolStamp = timeStamp.Cache(TextLabel, RightNow, "$timeDifference ago")

$timeDifference returns “0 Seconds”
The textlabel’s Text property will update every second for how many seconds ago the RightNow variable was, until the RightNow variable turns into minutes, which then it will minimalize the resources and only appropriately update every minute.

$date returns “November 10th, 2024” if it was over a day ago, and all the other formatting keywords return parts of $date!
If it’s the same day as the DateTime given (on the client’s time zone), it will return “Today at 12:00 AM”
If it was yesterday (on the client’s time zone), it will return “Yesterday at 12:00 AM”
$date and all its sub-keywords don’t update at all, leaving the text property as is.

the TimeStamp module is object oriented, so make sure to keep it as a variable so that you can call myCoolStamp:Destroy() whenever you need to!
Or don’t keep it as a variable, that’s fine too! You can run timeStamp:FindTimeStamper(TextLabel) to grab a Cache’d time stamp attached to the given instance!

Use myCoolStamp:Toggle(act: boolean?) to activate/deactivate the updates!
Use myCoolStamp:EditFormat(newString: string?, priorityChange: boolean?) to change the given format of the timeStamp object!
Use myCoolStamp:Update() to force an update on the timeStamp object.

To those blind to links, here’s the raw link!

6 Likes

One more thing: THIS IS A MODULE FOR CLIENT-SIDED ONLY.
Please do NOT run this on server-sided scripts!

2 Likes

Would you consider making it work client-side and server-side?

I could do that but it the $date would be localized to whatever timezone the server’s in, is that fine?

2 Likes

That’ll probably be fine for most, you should just mention it

1 Like

New TimeStamp update!

New prefixes:

  • $hour - “06”

  • $minute - “07”

  • $second - “36”

  • $now - Updates $date, and all of its sub-prefixes with the time that it’s updating rather than what you TimeStamp.Cache the stamp with.

Server-Sided support!

New “timeZone” boolean argument in TimeStamp.Cache() exclusive to server scripts
Any cache’d stamp created on the Server side will require ALL arguments in TimeStamp.Cache() to be filled.
TimeStamp on server script