Timestamp

Might be a nice extra icon/feature for the Post/Comment tool bar if possible.

Thanks Rob, not possible right now.

Just as an update…

I mentioned it on the Discourse forum, in passing, the other evening - the response was basically that these things are typically added as plugins rather than being a part of the core functionality - one of their testers was kind enough to put this together;

Add this to your Admin > Customize > CSS/HTML > </head>

<script type="text/discourse-plugin" version="0.4">
    api.onToolbarCreate(toolbar => {
      toolbar.addButton({
        id: "updated_button",
        group: "extras",
        icon: "clock-o",
        perform: e => e.addText("Updated " + new Date().toString())
      });
    });
</script>

…in this post - not sure if you would be willing to try it out @Ben / @sampattuzzi but it could be a useful little addon. My only initial observation is that I’m not sure what format the Date().toString() is going to come out in.

Thanks Rob, @sampattuzzi could you integrate this code as suggested if it won’t conflict with your existing header-bar customisation?

I have added it but I’m not sure what it’s supposed to do.

Thanks… I will give it a go in a moment…

Updated Wed Oct 26 2016 19:39:10 GMT+0100 (GMT Daylight Time)

^^^^^^ the above was inserted by the clock icon… the date format could do with shortening perhaps, losing maybe the seconds, GMT+0100 (GMT Daylight Time) etc

I’ve been looking at ways to reformat the date and time part of the output, something in .Net which is really easy to do, in Javascript appears to be a PITA… what I have noticed is that new Date().toString() always creates the same format, even if the date of the month is say the 2nd, it will inject “02” rather than “2”, thus the bit of useful date / time info is always 21 characters long.

Altering this line in the script I believe will give the desired output;

perform: e => e.addText("_Updated " + new Date().toString().substring(0,21) + "_")

it’s a bit hacky for my liking, but with out creating a lot more script to manage the names of the days and months and then concatenate a string in the desired format it appears to be the simplest of solutions.

I see that the Discourse site is using JQuery, there is a dateFormat plugin for JQuery UI which I believe gives the functionality I would have expected, e.g. the ability to enter something more like this;

.formatDate('yy-mm-dd', new Date())

and then use hh:mm for hours and minutes, but I had no way to experiment with the JQuery support on the site so figured the hacky way above would perhaps do for now.

Also, I spotted that the plugin example provided from the kind person on the Discourse site didn’t include a title attribute for the icon, as such this appears when you hover over the clock;

I believe it can be corrected by adding this to the plugin;

title: 'Updated Timestamp'

so the full plugin would now look like this;

<script type="text/discourse-plugin" version="0.4">
    api.onToolbarCreate(toolbar => {
      toolbar.addButton({
        id: "updated_button",
        group: "extras",
        icon: "clock-o",
        title: "Updated Timestamp",
        perform: e => e.addText("_Updated " + new Date().toString().substring(0,21) + "_")
      });
    });
</script>

Good job, @sampattuzzi any reason not to implement this you can see?

Hey @sampattuzzi, any chance of applying the above code which includes a couple of tweaks to the original? I appreciate you are busy with the course content and so on but I figure the above isn’t more than a copy/paste into a file/screen via Discourse?

Any help appreciated :slight_smile:

1 Like

I’ve made this change @Rob, can you check it’s what you’re after and solve this reply and close the topic if it is?

1 Like

Having a look now…

Updated Tue Dec 20 2016 22:18

The output (above) is spot on, the title property for the icon is still missing I’m guessing, or my suggestive code above didn’t work, as it displays this when you hover over it:



Updated Tue Dec 20 2016 22:20

I’m an idiot…

I just read the message… initially I only spotted the opening square bracket the an en.

Was expecting those to not be there an it only say “Updated Timestamp”, like the others say “Emoji” or “Options” etc

Was this from the exact code I put above? If so, I’ll shoot across to the Discourse forum and see if anyone can offer a suggestion as to how to remove the square brackets and the en. parts…


Updated Tue Dec 20 2016 23:27

I have posted on Discourse to see if anyone can suggest a fix for the above square brackets and en. issue.


Updated Tue Dec 20 2016 23:53

Just received this back from CPRadio, one of their senior testers who supplied the original code, he suggests trying this;

<script type="text/discourse-plugin" version="0.4">
    api.onToolbarCreate(toolbar => {
      I18n.translations.en.js.updated_timestamp = "Updated Timestamp";
      toolbar.addButton({
        id: "updated_button",
        group: "extras",
        icon: "clock-o",
        title: "updated_timestamp",
        perform: e => e.addText("_Updated " + new Date().toString().substring(0,21) + "_")
      });
    });
</script>

I hadn’t realised that there was support for other languages already built in, nor would I have guessed this line of code… my bad…

If we could get this added and see how it fairs I would be grateful.

Duly updated, give that a go @Rob

@Rob Happy New Year again :slight_smile:

Is that now what you were hoping for?

I so wish I could test this now but am on mobile which obviously doesn’t proide the hover text… as soon as I can get my son and Five Night’s at Freddies off of my laptop I will check it out and let you know! :slight_smile:

And back at ya, hope its a happy and prosperous year for you goodself, family and team :slight_smile:


Updated Tue Jan 03 2017 17:16

My son has now completed night for at Five Nights at Freddies and has relinquished laptop control… (and they say it’s good to share?)…

I have just hovered over the icon and it is perfect and is working perfectly. Thank you.

I will close this thread and appreciate this as it’s something I tend to use a fair bit.

1 Like

Privacy & Terms