Project

Profile

Help

Support #4888

closed

Getting current-dateTime()/js:Date() in UI/browser

Added by David Cramer about 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2021-02-01
Due date:
% Done:

0%

Estimated time:
Applies to JS Branch:
Fix Committed on JS Branch:
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

I have a UI in which I would like to display some duration info along side certain dates. E.g. "Today at 4:00 pm (2 minutes ago)". Implementing this in xslt is easy enough, however the UI should really update this text as time marches on. If your browser stays open, at some point it should say "Yesterday at 4:00 pm (9 hours ago)".

The problem is that current-dateTime() always returns the time at which the window was loaded. I assume this is a 'no side-effects' thing. I've tried implementing a JavaScript function that returns Date().toISOString(). That works when the pages is loaded, but when the function is called a second time I'm getting "XError:ixsl:call: property 'isoDate' is not a function; code:SXJS0007"

This is pretty common thing to do in a UI, so I assume there's a way to do it with Saxon-JS that I haven't figured out. Any guidance would be appreciated!

Actions #1

Updated by John Lumley about 3 years ago

Assuming you are using SaxonJS2 then you can use saxon:timestamp() which gives the current time at the point of evaluation -

https://www.saxonica.com/documentation/index.html#!functions/saxon/timestamp

Sent from my iPad

On 1 Feb 2021, at 23:05, Saxonica Developer Community wrote:



Actions #2

Updated by David Cramer about 3 years ago

Thank you John! That works perfectly.

Actions #3

Updated by Norm Tovey-Walsh about 3 years ago

  • Status changed from New to Resolved
Actions #4

Updated by Debbie Lockett about 3 years ago

  • Status changed from Resolved to Closed

Please register to edit this issue

Also available in: Atom PDF Tracking page