Script column not updating (randomly)

Using this script column from the forum

Age column
//v1.3 - 4 September 2021
//- added config options to set both auto-calculated Age Created and Age Modified column decimal place accuracy 
//- renamed columns
//v1.2 - 10 December 2016
//- split columns out into auto and unit options, rather than config options
//v1.1 - 9 December 2016
//- updated to work with multicol appropriately (thanks tbone!)
//v1.0 - 27 November 2016
//- initial release based on tbone's ModifiedWithin column script (http://resource.dopus.com/viewtopic.php?f=35&t=23192)
/*
can put your columns into the main categories now,
Don't think it's fully documented yet,
but with script columns it's set via ScriptColumn.category,
which takes one of these string values:

"loc"
"date"
"size"
"std"
"dims"
"image"
"music"
"prog"
"doc"
"movie"
"sums"
"script"
"shell"
"other"
"eval"
*/


//==================================================
function OnInit(data) 
{
   //uid added via script wizard (do not change after publishing this script)
   var uid = "4CBC870D-C8E5-435F-8F68-FA1AA7E16DBB";

   //resource center url added via script wizard (required for updating)
   var url = ""
   data.name = "Age";
   data.group = "Columns";
   data.desc = "Adds sortable columns that indicate folder/file age since creation or modification"
   data.copyright = "(c) 2016 Chuck"
   data.url = "http://resource.dopus.com/viewtopic.php?f=35&t=28433"
   data.version = "1.3"
   data.min_version = "12.24"
   data.default_enable = true;


   //==================================================
   function ConfigHelper(data)
   {
      this.data=data; this.descriptions=null; this.last=null;
      this.add = function(name, val, description)
      {
         this.data.config[name]=val; this.last=[this.data.config[name],name];
         if (description!=undefined) this.des(description); return this;
      }
      this.des = function(description)
      {
         if (!(description && DOpus.version.AtLeast("11.6.1"))) return this;
         if (!this.descriptions)
         { 
           this.descriptions=DOpus.NewMap();
           data.config._descriptions=this.descriptions; 
         }
         this.descriptions(this.last[1])=description; return this;
      }
      this.val = function(val)
      {
         if (typeof this.last[0]=="object") this.last[0].push_back(val);
         else this.last[0]=val; return this;
      }
   }


   //==================================================
   var cfg = new ConfigHelper(data);
   cfg.add("Column.Width", "60px").des("Standard column width");
   cfg.add("Column.Justify", DOpus.Create.Vector()).des("Column text alignment right, left or center").val(0).val("right").val("left").val("center");
   cfg.add("Accuracy_Auto_Created", "0").des("Decimal place accuracy for automatically calculated Age-Created column");
   cfg.add("Accuracy_Auto_Modified", "0").des("Decimal place accuracy for automatically calculated Age-Modified column");	  
}




//==================================================
function OnAddColumns(data) 
{

	var cmd = data.AddColumn();
	cmd.multicol = true;
	cmd.name = "TimeSinceModified";
	cmd.label = "- Age : Time Since Modification (Auto)";
	cmd.header = "Age (modified)";
	cmd.category = "date";
	cmd.method = "Auto";
	cmd.autorefresh = true;
	cmd.namerefresh = true;
	cmd.defwidth = Script.config["Column.Width"];
	cmd.type = "text";
	var justify = ["right","left","center"]
	cmd.justify = justify[Script.config["Column.Justify"]];

	var cmd = data.AddColumn();
	cmd.multicol = true;
	cmd.name = "TimeSinceCreated";
	cmd.label = "- Age : Time Since Creation (Auto)";
	cmd.header = "Age (created)";
	cmd.category = "date";
	cmd.method = "Auto";
	cmd.autorefresh = true;
	cmd.namerefresh = true;
	cmd.defwidth = Script.config["Column.Width"];
	cmd.type = "text";
	var justify = ["right","left","center"]
	cmd.justify = justify[Script.config["Column.Justify"]];
	
	var cmd = data.AddColumn();
	cmd.multicol = true;
	cmd.name = "TimeSinceModifiedUnits";
	cmd.label = "- Age : Time Since Modification (Units)";
	cmd.header = "Age (modified)";
	cmd.category = "date";
	cmd.method = "Units";
	cmd.autorefresh = true;
	cmd.namerefresh = true;
	cmd.defwidth = Script.config["Column.Width"];
	cmd.type = "text";
	var justify = ["right","left","center"]
	cmd.justify = justify[Script.config["Column.Justify"]];

	var cmd = data.AddColumn();
	cmd.multicol = true;
	cmd.name = "TimeSinceCreatedUnits";
	cmd.label = "- Age : Time Since Creation (Units)";
	cmd.header = "Age (created)";
	cmd.category = "date";
	cmd.method = "Units";
	cmd.autorefresh = true;
	cmd.namerefresh = true;
	cmd.defwidth = Script.config["Column.Width"];
	cmd.type = "text";
	var justify = ["right","left","center"]
	cmd.justify = justify[Script.config["Column.Justify"]];
}




//==================================================
function Auto(data) 
{
	var dateMod = new Date(data.item.modify).valueOf();
	var dateCre = new Date(data.item.create).valueOf();
	var dateNow = new Date().valueOf();
	var diffCre = (dateNow-dateCre)/60000;
	var diffMod = (dateNow-dateMod)/60000;
	var accuracy_ac = Number(Script.config["Accuracy_Auto_Created"]);
	var accuracy_am = Number(Script.config["Accuracy_Auto_Modified"]);

	//setting defaults (no value to clutter columns)
	data.columns("TimeSinceCreated").value = "---";
	data.columns("TimeSinceModified").value = "---";
	
	//Determine age in minutes since file/folder created and add appropriate suffix to calculation
	if (diffCre < 60)
    {
		data.columns("TimeSinceCreated").value = (diffCre).toFixed(0) + " min";
	}	
    else if (diffCre < 1440)
    {
		data.columns("TimeSinceCreated").value = ((diffCre)/60).toFixed(accuracy_ac) + " hrs";
	}   
    else if (diffCre < 525960)
    {
		data.columns("TimeSinceCreated").value = ((diffCre)/1440).toFixed(accuracy_ac) + " days";
	}
    else 
    {
		data.columns("TimeSinceCreated").value = ((diffCre)/525960).toFixed(accuracy_ac) + " yrs";
	}
	data.columns("TimeSinceCreated").sort = diffCre;
	
	//Determine age in minutes since file/folder modified and add appropriate suffix to calculation
	if (diffMod < 60)
    {
		data.columns("TimeSinceModified").value = (diffMod).toFixed(0) + " min";
	}	
    else if (diffMod < 1440)
    {
		data.columns("TimeSinceModified").value = ((diffMod)/60).toFixed(accuracy_am) + " hrs";
	}   
    else if (diffMod < 525960)
    {
		data.columns("TimeSinceModified").value = ((diffMod)/1440).toFixed(accuracy_am) + " days";
	}
    else 
    {
		data.columns("TimeSinceModified").value = ((diffMod)/525960).toFixed(accuracy_am) + " yrs";
	}
	data.columns("TimeSinceModified").sort = diffMod;
}




//==================================================
function Units(data) 
{
	var dateMod = new Date(data.item.modify).valueOf();
	var dateCre = new Date(data.item.create).valueOf();
	var dateNow = new Date().valueOf();
	var diffCre = (dateNow-dateCre)/60000;
	var diffMod = (dateNow-dateMod)/60000;
	var y = d = h = m = sc = sm = 0;

	//setting defaults (no value to clutter columns)
	data.columns("TimeSinceCreatedUnits").value = "---";
	data.columns("TimeSinceModifiedUnits").value = "---";
	
	//Determine age since file/folder created and add appropriate suffix to calculation
	sc = (dateNow-dateCre)/1000;
	switch (true) 
    {
	case (sc > 31557600):
		y = Math.floor(sc / 31557600);
		sc %= 31557600;
	case (sc > 86400):
		d = Math.floor(sc / 86400);
		sc %= 86400;
	case (sc > 3600):
		h = Math.floor(sc / 3600);
		sc %= 3600;
	case (sc > 60):
		m = Math.floor(sc / 60);
		sc %= 60;
		sc = sc.toFixed(0);
	case (sc >= 0):
		m = 0;
		sc = 0;
		sc = sc.toFixed(0);
	}
	
	//Determine age since file/folder modified and add appropriate suffix to calculation
	sm = (dateNow-dateMod)/1000;
	switch (true) 
    {
	case (sm > 31557600):
		y = Math.floor(sm / 31557600);
		sm %= 31557600;
	case (sm > 86400):
		d = Math.floor(sm / 86400);
		sm %= 86400;
	case (sm > 3600):
		h = Math.floor(sm / 3600);
		sm %= 3600;
	case (sm > 60):
		m = Math.floor(sm / 60);
		sm %= 60;
		sm = sm.toFixed(0);
	}
	
	//Correct numbers < 10 to add leading 0
	var yy = y.toString();
	var dd = d.toString();
	var hh = h.toString();
	var mm = m.toString();
	var ssc = sc.toString();
	var ssm = sm.toString();
	
	yy = yy.replace(yy, (y < 10) ? "0" + y : y);
	dd = dd.replace(dd, (d < 10) ? "0" + d : d);
	dd = dd.replace(dd, (dd < 100) ? "0" + dd : dd); //add second leading 0 since may have > 99 days
	hh = hh.replace(hh, (h < 10) ? "0" + h : h);
	mm = mm.replace(mm, (m < 10) ? "0" + m : m);
	ssc = ssc.replace(ssc, (sc < 10) ? "0" + sc : sc);
	ssm = ssm.replace(ssm, (sm < 10) ? "0" + sm : sm);
	
	//Format columns to display
	var fc = yy + ':' + dd + ':' + hh + ':' + mm + ':' + ssc;
	data.columns("TimeSinceCreatedUnits").value = fc;
	data.columns("TimeSinceCreatedUnits").sort = diffCre;
	
	var fm = yy + ':' + dd + ':' + hh + ':' + mm + ':' + ssm;
	data.columns("TimeSinceModifiedUnits").value = fm;
	data.columns("TimeSinceModifiedUnits").sort = diffMod;
}




//==================================================
function OnScriptConfigChange(data) 
{
	Script.InitColumns();
	Script.RefreshColumn("TimeSinceCreated");
	Script.RefreshColumn("TimeSinceModified");
	Script.RefreshColumn("TimeSinceCreatedUnits");
	Script.RefreshColumn("TimeSinceModifiedUnits");
}




///////////////////////////////////////////////////////////////////////////////
function OnAboutScript(data)
{ //v0.1
   var cmd = DOpus.Create.Command();
   if (!cmd.Commandlist('s').exists("ScriptWizard"))
   {
      if (DOpus.Dlg.Request("The 'ScriptWizard' add-in has not been found.\n\n" +
"Install 'ScriptWizard' from [resource.dopus.com].\nThe add-in enables this dialog and also offers " +
"easy updating of scripts and many more.","Yes, take me there!|Cancel", "No About.. ", data.window))
      cmd.RunCommand('http://resource.dopus.com/viewtopic.php?f=35&t=23179');
   }
   else
      cmd.RunCommand('ScriptWizard ABOUT WIN='+data.window+' FILE="'+Script.File+'"');
}
//MD5 = "8f56f14954a42d94d8c5cd5181afb987"; DATE = "2016.12.09 - 20:17:45"

gives these results when new files are added (using a batch scaling routine in this case) (rightmost column)


the scaling routine is creating a .tmp file first then that gets updated to a .png file.
As you can see some files do not get updated by the script column and some do (refreshing does fix this but is an additional unnecessary step in the workflow) - indicating some internal glitch as there seems to be nothing wrong with the code.

Isn't this a great opportunity to use Age instead?

Thanks already used DateDiff
Here is simple evaluator column that does the same the job but no bug as described above, it can be adapted to similar columns if desired (requires knowledge of evaluator colmuns), just copy and paste into evaluator columns

<?xml version="1.0"?>
<evalcolumn align="2" attrrefresh="yes" autorefresh="yes" category="date" customgrouping="no" foldertype="all" header="Age (created)" keyword="agecreated" maxstars="5" namerefresh="yes" reversesort="no" title="Age (created)" type="0">date_now		= Now();
when_created 	= createddate;

mins	= Abs(DateDiff(&quot;n&quot;, date_now, when_created));
hours	= Abs(DateDiff(&quot;h&quot;, date_now, when_created));
days	= Abs(DateDiff(&quot;d&quot;, date_now, when_created));
weeks 	= Abs(DateDiff(&quot;w&quot;, date_now, when_created));
months 	= Abs(DateDiff(&quot;m&quot;, date_now, when_created));
years 	= Abs(DateDiff(&quot;yyyy&quot;, date_now, when_created));

return_value = &quot;---&quot;;

if (operation == &quot;sort&quot;)
	return createddate;
	
if (years &gt; 0)
  {
    return_value = years &gt; 1 ? years + &quot; years&quot; : years + &quot; year&quot;;
  }
elseif (days &gt; 0)
  {
    return_value = days &gt; 1 ? days + &quot; days&quot; : days + &quot; day&quot;;
  }
elseif (hours &gt; 0) 
  {
    return_value 	= hours &gt; 1 ? hours + &quot; hours &quot; : hours + &quot; hour &quot;;
	mins_left_over 	= mins - (hours * 60);
    return_value 	+= mins_left_over &gt; 1 ? mins_left_over + &quot; minutes&quot; : mins_left_over + &quot; minute&quot;;
  }
elseif (mins &gt; 0)
  {
    return_value = mins &gt; 1 ? mins + &quot; minutes&quot; : mins + &quot; minute&quot;;
  }
else
  {
    return_value = &quot;0 minutes&quot;;
  }


return return_value;

//return (weeks / 52 &gt; 0) ? ((weeks / 52 &gt; 1) ? (weeks / 52) + &quot; yrs&quot; : (weeks / 52) + &quot; yr&quot;)    : weeks + &quot; wks&quot;;</evalcolumn>

1 Like

Nice alternative. Have you noticed any issues with sorting by the column?

appears to be sorting ascending/descending correctly - folder & files sorted separately.

EDIT: further investigation, years and days and probably hours not sorted properly. Is there a solution ? nvm. found it - the evaluator column above has been updated to reflect changes.

Works well, thanks!

Well, this thread is already posted as a bug-report.

I down loaded the first version and pasted into an Evaluator Column.
I then down loaded the second version and also pasted into an Evaluator Column.

So yes, I can see that there are internal Evaluator coding differences.
But, despite all external parameters being the same, two seemingly identical listings were created within Preferences / File Display Columns / Evaluator Columns.

However there is only one header context menu Columns -> Date and Time -> Age (created) listing.

Is there an easy test to determine which one is working ?

2024-12-31-21-16-28-544x46

add this to the evaluator one

or this

@galaxyhub
Yes, then both are listed in the context menu.
Thanks.

@Jon @Leo - Getting some strange results from

when_created 	= createddate;
hours	= Age(when_created, "h");

and

date_now		= Now();
when_created 	= createddate;
hours	= Abs(DateDiff("h", date_now, when_created);

Created is the DO Created (date and time) column
Age (created) is the evaluator column

when hours is changed to

when_created 	= createddate;
mins	= Age(when_created, "n");
hours 	= Abs(mins / 60);

the problem is resolved.

here is the ammended evaluator column for anyone using the above one.

<?xml version="1.0"?>
<evalcolumn align="2" attrrefresh="yes" autorefresh="yes" category="date" customgrouping="no" foldertype="all" header="Age (created)" keyword="Agecreated" maxstars="5" namerefresh="yes" reversesort="no" title="Age (created)" type="0">date_now		= Now();
when_created 	= createddate;

mins	= Age(when_created, &quot;n&quot;);
hours	= Age(when_created, &quot;h&quot;);  // buggy
hours 	= Abs(mins / 60);
days	= Age(when_created, &quot;d&quot;);
weeks 	= Age(when_created, &quot;w&quot;);
months 	= Age(when_created, &quot;m&quot;);
years 	= Age(when_created, &quot;yyyy&quot;);

return_value = &quot;---&quot;;

if (operation == &quot;sort&quot;)
	return createddate;
	
if (years &gt; 0)
  {
    return_value = years &gt; 1 ? years + &quot; years&quot; : years + &quot; year&quot;;
  }
elseif (days &gt; 0)
  {
    return_value = days &gt; 1 ? days + &quot; days&quot; : days + &quot; day&quot;;
  }
elseif (hours &gt; 0) 
  {
    return_value 	= hours &gt; 1 ? hours + &quot; hours &quot; : hours + &quot; hour &quot;;
	mins_left_over 	= mins - (hours * 60);
    return_value 	+= mins_left_over &gt; 1 ? mins_left_over + &quot; minutes&quot; : mins_left_over + &quot; minute&quot;;
  }
elseif (mins &gt; 0)
  {
    return_value = mins &gt; 1 ? mins + &quot; minutes&quot; : mins + &quot; minute&quot;;
  }
else
  {
    return_value = &quot;0 minutes&quot;;
  }

return return_value;
</evalcolumn>