Jump to content

Spotfire Terr - Date and DateTime conversion


Eric Flodin

Recommended Posts

I'm trying to write a simple R script that passes in a Document Property of type Date, creates two new date variables that are +/- 180 days from the original date, and passes the new dates out to a Document Property of type Date.

I've tried various iterations on the script, and have had success if the output variables sent to a Document Property that is type DateTime, however, I need them to be of type Date.

For example, this script worked (but output is DateTime, which doesn't suit my needs):

 

jobDate

Link to comment
Share on other sites

TERR/R "POSIXct" objects are sent to Spotfire as Spotfire "DataTime" objects and TERR/R "Date" objects become Spotfire "Real" objects (the Data class is ignored), as you noticed.  There is no way to avoid this translation.

 

I don't know how to let a Spotfire DateTime object become the value of a Spotfire Date property.

 

 

Link to comment
Share on other sites

You may find the information from the following public Spotfire knowledge base article helpful as background for this question:

 

~~~~~~~~~~~~~~~~~~~~~

 

https://support.tibco.com/s/article/ka11a000000HsvpAAC/What-TERR-object-...

 

 

Details

 

What TIBCO Enterprise Runtime for R (TERR) object class does the Spotfire data function framework recognize as date/time information

 

 

Resolution

 

 

Spotfire data functions recognize TERR objects of class "POSIXct" as date/time information. As designed, the Spotfire/TERR data function interface for date/time information does the following:

 

- Converts a Spotfire value or column whose DataType is "Date", "Time" or "DateTime" into a TERR object of class "POSIXct".

 

- Converts a TERR object of class "POSIXct" into a Spotfire value or column with a DataType of "DateTime", which can then be formatted in Spotfire to display only the date (or to display only the time) if needed.

 

This interface does not use any other TERR object classes (such as the "Date" class in TERR) to transfer date/time information between Spotfire and TERR.

 

Additional notes:

 

1). The Sys.Date() function in TERR returns a TERR/R object of class "Date" which the Spotfire/TERR data function interface does not treat as date/time information. Because of this, a TERR object of class "Date" will be imported into Spotfire as a numeric column with a DataType of "Real" and values that correspond to the time span in days between each cell's date and the TERR/R "Date" class's 1/1/1970 reference date.

 

>

> Sys.Date()

[1] "2017-05-12"

>

> class( Sys.Date() )

[1] "Date"

>

 

2). The Sys.time() function in TERR returns a TERR/R object of class "POSIXct" which the data function interface converts into a Spotfire value or column with a DataType of "DateTime".

 

>

> Sys.time()

[1] "2017-05-12 08:50:21 PDT"

>

> class( Sys.time() )

[1] "POSIXct" "POSIXt"

>

>

~~~~~~~~~~~~~~~~~~~~~

Link to comment
Share on other sites

  • 3 years later...

On approach is to allow the TERR Data Function to return the value to a Document Property of Data type DateTime, and then use an IronPython script to (automatically) update another Document Property of Data type Date. The IronPython code is simple.

x = Document.Properties["MyDateTimeDocProp"]

Document.Properties["MyDateDocProp"] = x.ToShortDateString()Have the script execute whenever the Document Property "MyDateTimeDocProp" changes.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...