Format list to show how many minutes ago a point was created

583
6
Jump to solution
04-14-2023 11:50 AM
dwold
by
Occasional Contributor II

I have a list and I want to display how old or how long ago a point was created. Is there a way to write this out so the list reads with the Incident and below it says: Occurred X Hours X Minutes ago

dwold_0-1681498173424.png

 

@jcarlson 

@KenBuja 

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

This was tested in a List

var creationTime = $datapoint.LASTUPDATE;
var diff = DateDiff(Now(), creationTime, 'minutes');
var output = `It hasn't occurred yet`;
if (diff > 0) { 
  var hours = Floor(diff/60)
  var minutes = Floor(diff - (hours * 60))
  if (diff < 60) {
    output = `Occurred ${minutes} minutes ago`
  } else {
    output = `Occurred ${hours} hours ${minutes} minutes ago`
  }
}
return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     elapsed: output
   }
}

In the Line item template section, add in "{expression/elapsed}".

This is what my testing List looks like:

list.png

View solution in original post

6 Replies
KenBuja
MVP Esteemed Contributor

Here's one way to do it.

Edit...made a few modifications

 

var creationTime = $feature.LASTUPDATE;
var diff = DateDiff(Now(), creationTime, 'minutes')
if (diff < 0) return `It hasn't occurred yet`
var hours = Floor(diff/60)
var minutes = Floor(diff - (hours * 60))
if (diff < 60) return `Occurred ${minutes} minutes ago`
return `Occurred ${hours} hours ${minutes} minutes ago`

 

0 Kudos
dwold
by
Occasional Contributor II

@KenBuja thanks for your help with this. Did I input this correctly? I'm not to the advanced formatting section.

dwold_0-1681503450993.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

My apologies, this was tested in the Playground, not an indicator. Give this a try

var creationTime = $datapoint.LASTUPDATE;
var diff = DateDiff(Now(), creationTime, 'minutes');
var output = `It hasn't occurred yet`;
if (diff > 0) { 
  var hours = Floor(diff/60)
  var minutes = Floor(diff - (hours * 60))
  if (diff < 60) {
    output = `Occurred ${minutes} minutes ago`
  } else {
    output = `Occurred ${hours} hours ${minutes} minutes ago`
  }
}
return {
    //textColor:'',
    //backgroundColor:'',
    topText: output,
    //topTextColor: '',
    //topTextOutlineColor: '',
    //topTextMaxSize: 'medium',

 

0 Kudos
dwold
by
Occasional Contributor II

@KenBuja Getting closer...I think. Not knowing much about arcade expressions, is having the date with the time causing an issue?

dwold_0-1681737636971.png

Attribute table:

dwold_1-1681737711178.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

This was tested in a List

var creationTime = $datapoint.LASTUPDATE;
var diff = DateDiff(Now(), creationTime, 'minutes');
var output = `It hasn't occurred yet`;
if (diff > 0) { 
  var hours = Floor(diff/60)
  var minutes = Floor(diff - (hours * 60))
  if (diff < 60) {
    output = `Occurred ${minutes} minutes ago`
  } else {
    output = `Occurred ${hours} hours ${minutes} minutes ago`
  }
}
return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     elapsed: output
   }
}

In the Line item template section, add in "{expression/elapsed}".

This is what my testing List looks like:

list.png

dwold
by
Occasional Contributor II

@KenBuja That worked! Thank you s much for your help, I appreciate it!

0 Kudos