Skip to main content
18-Opal
January 30, 2024
Solved

Add date to comments

  • January 30, 2024
  • 2 replies
  • 1330 views

Currently we have an acl script that adds the username to any comments that are inserted. There has been a request to add the date. Is there a way to only have the date? Under functions there is no date only option., only a time_date function.

 

function insert_tag_after_callback(doc, tagname, oid, op) {

if (op==1) { return 0; }

if (tagname == "_comment") {

goto_oid(oid);

insert("[" . time_date() . ", " . username() . "]: ");

}

}

 

doc_add_callback(0, "insert_tag_after", "insert_tag_after_callback");

 

Thanks

Bryon

Best answer by bfriesen

Thanks to Gareth and PTC support for their help. The code below will give you the date and username output in a comment. If you want the time and date use the code in the first post. To add this to your environment, Create an acl file in the editinit folder and paste the code below into it.

 

function insert_tag_after_callback(doc, tagname, oid, op) {

 

if (op==1) { return 0; }

 

if (tagname == "_comment") {

 

goto_oid(oid);

 

insert("[".substr(time_date(),1,10).", ".substr(time_date(),21,4).",".username()."]:")

$x=substr(time_date(),1,10);gsub(" "," ",$x)

}

}

doc_add_callback(0, "insert_tag_after", "insert_tag_after_callback");

2 replies

16-Pearl
January 30, 2024

You might have to do a little work to get the date in the format you need, e.g., the docs say that time_date() produces something like "Mon Dec 28 17:23:52 1992". You want to fish out the "Dec 28" part and the year, I'm guessing?

 

You can use one of the regular expression functions to do the string manipulation - sub() or match() are probably most helpful here. With sub() you can clear out the bits of the text you don't want.

 

text = time_date()

sub(/^.* /, "", text)

 

I haven't tested, but something like the above would clear the day name out from the string, and you could keep going to clear the timestamp too.

bfriesen18-OpalAuthorAnswer
18-Opal
February 20, 2024

Thanks to Gareth and PTC support for their help. The code below will give you the date and username output in a comment. If you want the time and date use the code in the first post. To add this to your environment, Create an acl file in the editinit folder and paste the code below into it.

 

function insert_tag_after_callback(doc, tagname, oid, op) {

 

if (op==1) { return 0; }

 

if (tagname == "_comment") {

 

goto_oid(oid);

 

insert("[".substr(time_date(),1,10).", ".substr(time_date(),21,4).",".username()."]:")

$x=substr(time_date(),1,10);gsub(" "," ",$x)

}

}

doc_add_callback(0, "insert_tag_after", "insert_tag_after_callback");