Jump to content

Display Start or End Time in Specific Format


Recommended Posts

  • Seeq Team

Various parts of the world display date and time stamps differently. Often times, we get requests for changing the order of month and day in the timestamp string or to display the date as a Scorecard metric in a specific format. This can be done using the replace() operator in Formula.

For example, let's say we wanted to pull the start time for each capsule in a condition and display it as mm/dd/yyyy hh:mm format:

$condition.transformToSamples($cap -> 
Sample($cap.getStart(),$cap.getProperty('Start')), 1d)
.replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , '${month}/${day}/${year} ${hour}:${minute}')

This takes the original timestamp (for example: '2019-11-13T17:04:13.7220714157Z') and parses it into the year, month, day, hour, minute, second, and decimal to be able to set up any format desired. The various parts of the string can then be called in the second half of the replace to get the desired format as shown above with ${month}/${day}/${year} ${hour}:${minute}. From there, you can either view this data in the trend or use Scorecard Metric to display the Value at Start in a condition based metric.

If the end time is desired instead of the start, the only changes needed would be to (1) switch the .getStart operator to .getEnd, and (2) switch the .getProperty('Start') to .getProperty('End').

Note: The '1d' at the end of the 2nd line of the formula represents the maximum interpolation for the data, which is important if you want to view this as a string signal. This value may need to be increased depending on the prevalence of the capsules in the condition. 

  • Like 4
Link to comment
Share on other sites

  • 4 months later...
  • Seeq Team

The formula above needs some tweaks for new version of Seeq to be compatible with upgrades to Seeq Formula

For 0.48:

$condition.transformToSamples($cap -> 
Sample($cap.getStart(),$cap.getStart().toString()), 1d)
.replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , '${month}/${day}/${year} ${hour}:${minute}')

For 0.49

$condition.toSamples($cap -> Sample($cap.startKey(), $cap.startKey().toString()), 1d)
   .replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , 
            '${month}/${day}/${year} ${hour}:${minute}')

All that said, even back in 0.47, the more succinct way to express this is

$condition.toSignal('Start').toLinear(1d).toString()
  .replace('/(?<year>....)-(?<month>..)-(?<day>..)T(?<hour>..):(?<minute>..):(?<sec>..)(?<dec>.*)Z/' , 
           '${month}/${day}/${year} ${hour}:${minute}')

 

  • Like 2
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
 Share

×
×
  • Create New...