Add a second t_stamp to a dataset is failing

I’m trying to show both the epoch and local standard time next to each other from the output of a system.tag.queryTagHistory result.

The function call works fine, I’m putting the result on a custom value in the root of a page. Then I added a script transform to duplicate the t_stamp as t_stamp_readable and tried to add it as a java.util.timestamp but when I try to add the column to a dataset, it throws an error that I cant add a timestamp to a dataset.

Am I doing something wrong or should I try to add it as a string or something else? Any suggestions? Thanks!

Show the error(s) you are getting here. Post either your code or an example of the code you are using to attempt to add a column to the dataset. Make sure to post it as pre-formatted text, see Wiki - how to post code on this forum .

Line 9 is the return and the error is with java.sql.timestamp. Changing the type to str and java.util.date threw errors too. date couldn’t be coerced to a string and cant put a java.sql.timestamp into a java.util.date respectively. Thanks!

CODE:

def transform(self, value, quality, timestamp):
	import java.sql.Timestamp
	
	newColumneData = []
	for row in range(value.getRowCount()):
		tstamp_new = value.getValueAt(row, 't_stamp')
		newColumneData.append(tstamp_new)
	
	return system.dataset.addColumn(value, 0, newColumneData, 't_stamp_readable', java.sql.Timestamp)	

ERROR:

Error_ScriptEval(“Traceback (most recent call last): File ““, line 9, in transform TypeError: Cant put element of type timestamp in dataset. “)

If you must manipulate time zone display yourself, you will suffer with java.util.Date and its subclasses (which includes java.sql.Timestamp) because they are zone-less objects. They parse and stringify in the JVM's default time zone, and you cannot use datetime arithmetic to correct this (produces subtle bugs).

Instead, create a java.time.Instant, and then a ZonedDateTime in the desired zone to print. That can be stringified reliably. (Use a date/time formatter for precise control.)

You will need to use the Dataset Builder. Which will allow you to specify the types for the columns.

Thanks for the input, do you recommend a different way to display the same date twice from the queryTagHistory function? I’m not married to the idea of adding it twice if there is a better way, thanks again!

Adding another column to the source data is reasonable, but it should be a string produced from a ZonedDateTime, not another date object. Objects that aren't native JSON don't transfer to the front-end well.

If displaying in a Perspective table, you might avoid adding the raw data column by using a column render view that takes the one column and display both forms. (This will really only be helpful for large virtualized tables.)

1 Like

Is a column render view a sub view or something different? Thanks!

See Embedding a view in a table-cell.

1 Like