Files
ttyverse-extensions/timestamp.pl
2025-07-29 11:29:27 -04:00

60 lines
1.9 KiB
Perl

# TTYverse Timestamp Extension
# Modified by Storm Dragon: https://stormux.org/
# Support Storm Dragon's work: https://patreon.com/stormux
# Original concept from kosertech.com (see ttyverse.wiki/Extension-Development.md for development guide)
# Published under the Floodgap Free Software License: http://www.floodgap.com/software/ffsl/
# What is it?
# This extension adds timestamps before posts when 5 minutes or more have passed
# between timeline updates, helping organize the flow of your fediverse timeline.
# Usage:
# This extension works automatically. Load it when you start TTYverse or add it
# to your configuration. The timestamp format is: -- HH:MMAM/PM --
$handle = sub {
my $delayInSeconds = 60 * 5; # 5 minutes default
my ($nsec,$nmin,$nhour,$nday,$nmon,$nyear) = localtime(time);
# Initialize timestamp tracking on first run
if(!$Lib_firstrun){
$Lib_firstrun = 1;
print "-- TTYverse timestamp extension loaded\n" if (!$silent);
$Lib_past = time;
}
# Print timestamp if enough time has elapsed
if($Lib_past < (time - $delayInSeconds)){
$Lib_past = time;
my $timeString = "-- ";
my $timeOfDay = "AM";
# Convert to 12-hour format
if ($nhour >= 12) {
if ($nhour > 12) {
$nhour = $nhour - 12;
}
$timeOfDay = "PM";
}
if (($nhour < 10) && ($nhour != 0)) {
$timeString .= "0";
}
if ($nhour == 0) {
$nhour = 12;
$timeOfDay = "AM";
}
$timeString .= "$nhour:";
if ($nmin < 10) {
$timeString .= "0";
}
$timeString .= "$nmin$timeOfDay";
print $streamout "$timeString --\n" if (!$silent);
}
# Allow TTYverse to handle displaying the post normally
my $ref = shift;
&defaulthandle($ref);
return 1;
};