UTC with format:date?

So when using <<now>> you can prefix the format with [UTC] to get the utc time, however I’m not sure how to achieve this using format:date.

Here’s what I have so far, I’m just trying to create some text that onHover lets me see the local time, but otherwise shows the UTC time of the last modified tiddler.

<$let 
local={{{ [haschanged[]get[modified]format:date[YYYY-0MM-0DD @ 0hh:0mm:0ss TZD]!sort[modified]] -[prefix[$:/state/]] -[prefix[$:/temp/]] -[prefix[$:/StoryList]] -[prefix[$:/HistoryList]] +[limit[1]] }}}

utc="<$text text={{{ [haschanged[]get[modified]format:date[YYYY-0MM-0DD @ 0hh:0mm:0ss]!sort[modified]] -[prefix[$:/state/]] -[prefix[$:/temp/]] -[prefix[$:/StoryList]] -[prefix[$:/HistoryList]] +[limit[1]] }}} >"
>
	<div class="tc-site-update">
		<small>
			<$button to="" class="tc-btn-invisible" tooltip=<<local>> >	
				''Last updated:'' <<utc>>
			</$button>
		</small>
	</div>
</$let>

The modified field value is a UTC datetime value.

The format:date filter operator automatically converts to local time, unless the [UTC] prefix is included in the operand value.

However, you can’t specify [UTC] directly as a literal format value in the operand because the square brackets don’t “nest”. To work around this syntax limitation, you can first define the format using a variable, and then reference the variable as the operand value, like this:

<$let ...
format="[UTC]YYYY-0MM-0DD @ 0hh:0mm:0ss TZD"
utc={{{ [haschanged[]get[modified]format:date<format>!sort[modified]] -[prefix[$:/state/]] -[prefix[$:/temp/]] -[prefix[$:/StoryList]] -[prefix[$:/HistoryList]] }}}>

Note:

  • You don’t need to include the $text widget in the assignment since the <<utc>> reference doesn’t contain any wiki link syntax so it will render as text anyway.
  • You don’t need the +[limit[1] filter run, since the “filtered transclusion” will always use the first value when it is used to set a variable in the $let widget.
2 Likes

that work arounds awesome, thank you, I think I can use that in other things I’m working on too :grin:

Huh, didn’t realize that, I was thinking that if I had it wrapped in triple curly brackets it would convert to a link, and the reason it didn’t in the tooltip is because it only shows plaintext in the tooltips.

Didn’t know that, it was a bit of reused code from another experiment of mine :sweat_smile: