Need help with creating a timestamp button with adjustable formatting

I decided to create a new editor toolbar button that, upon clicking, is meant to put a timestamp whereever the text cursor is located using $:/language/Tiddler/DateFormat as the default format if the target tiddler doesn’t have the field timestamp-format with anything in it.

Well… it, sort of works? I have the tiddler $:/core/ui/EditorToolbar/timestamp with the text:

<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="insert-text"
	text={{{ [<targetTiddler>has[timestamp-format]then<now>format:date{!!timestamp-format}else<now>format:date{$:/language/Tiddler/DateFormat}] }}}
/>

For some some reason, the inserted text shows as 00-1-12-31 23:43:52 (the format in $:/language/Tiddler/DateFormat is YYYY-0MM-0DD 0hh:0mm:0ss) and it doesn’t matter if timestamp-format exists or not.

Any help with figuring out why this is the case would be greatly appreciated :sweat_smile:

The default output of the <now> macro is a local-time formatted string using “0hh:0mm, DDth MMM YYYY”, but format:date[...] filter operator expects the input to be a 17-digit system UTC datetime string using “[UTC]YYYY0MM0DD0hh0mm0ss0XXX”.

Try this:

<$let format={{{ [<targetTiddler>get[timestamp-format]else{$:/language/Tiddler/DateFormat}] }}}>
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="insert-text"
	text={{{ [<now [UTC]YYYY0MM0DD0hh0mm0ss0XXX>format:date<format>] }}}
/>

-e

It works!

Thank you Eric :grin: and the explanation helps a ton, I was really confused by how it was reading the format.

Just gonna tack this on here, you can actually use this to very quickly add new custom text on click, like so: "timestamp-format": "| YYYY-0MM-0DD | |" so if you are keeping your own handtyped interstitial journal, or in my case an activity log, it’s as simple as either clicking the button or pressing the keyboard shortcut.

Just felt like sharing :wink:

EDIT: Actually, I did notice that the timestamp is off. For instance, instead of showing 2200, it is showing 0200. I imagine this is related to the UTC time, but I can’t seem to figure out how to change this? :thinking:

EDIT 2: Well, for the time being, changing the filter to {{{ [<now [UTC]YYYY0MM0DD0hh0mm0ss0XXX>add[200000000]format:date<format>] }}} will have to do

1 Like

thanks for sharing @Justin_H

fyi. I have 3 or 4 timestamp editor toolbar buttons some where with my preferred formats.

Interesting! mind if I ask why you decide to have multiple, and are you familiar with what might be going on with the now macro not using the local system time by chance?

The local system time is typicaly UTC so when we use a time stamp into text we usually want to use local time, as it gets fixed in place. So we need the now time to return local time.

If however we are using fields to store a time stamp, it is wise to also use UTC and when displaying it use the local time. The advantage being if you move to a new time zone (local timezone) all time stamps are “updated” relative to UTC. This is importiant for due dates and other comparisons.

  • Modified and created dates already use UTC

I will look for the multiple formats I decided on. And post back here.

Actualy here are three buttons, you can edit them to suit.

The first I edit to be what I want at the time, or just date, or just time.
Editor-time-date-stamps.json (3.7 KB)

In the control panel Appearence toolbars I often list additional buttons behind the more dropdown if used less often

1 Like

If you could give it a global shortcut of F5 and make it a standard plugin, then you’re off to the races!

fwiw, I use the solution described here, with ctrl-d as my shortcut key (mimicking tomboy notes).

I suspect the hotkey preference will vary widely according to what people are used to. I dont know what is most common out there (the above link suggests ctrl-g), but would be something worth a little research if this were to become a standard plugin

That’s a useful link and post!

I didn’t mean to be presumptuous and think that one hotkey or keyboard shortcut for a timestamp would be “standard”. But if a button/shortcut would be included in the “core”, might it be also in the customizable keyboard shortcuts list. I just threw F5 out there. In PowerPoint (and LibreOffice and OpenOffice), it means: run presentation. In Windows’ basic text editor (and no where else, apparently), it gives a timestamp. CTRL+F5 reloads the page. F5 seems to signal: bring us to the present or show us where we’re at.

oh interesting use of F5. I think I’ve encountered it in the “run presentation” sense once or twice over the years, but in general it’s a hotkey I just never use.

Perhaps most relevant though - in browsers it triggers a refresh. I don’t know how widely people use it in that way (I dont), but something to consider before changing it’s behaviour (assuming F_ keys can be remapped from the browser page level?)

edit/PS: just realised that firefox at least uses ctrl-D natively for bookmarks. That I remapped it many months ago and never realised just shows how much I dont use that particular feature myself.