Question
· Feb 1

Is there a simple way to check if a given class need to be recompiled ?

A class (and routine) definition can sometimes differ from it's compiled state.
When such a thing occurs, a "+" sign will be shown in the tab of the file opened in Studio.

I would like to do the same check programmatically.

For routines, it's very simple : 

set routine=##class(%Routine).%New(name)        
write routine.UpToDate

For classes, I could not find the equivalent. The only solution I found so far is to compare the compilation date and definition date :

set classCompiled = ##class(%Dictionary.CompiledClass).%OpenId(name)            
set classDefinition = ##class(%Dictionary.ClassDefinition).%OpenId(name)
write classDefinition.TimeChanged '= classCompiled.TimeCreated

Is there a better,  cleaner way ?
The main issue is that there is no proof that this is what Studio does. It probably use some more complex logic. There is a few cases where I got a "+" and it's undetected (and the opposite).

EDIT: 

Checking the status of the generated classes (.1.int files) helps a little bit : 

set routine=""
for
{	  				
    set timeStamp = classCompiled.Routines.GetNext(.routine) 		  			
    quit:routine=""
    set routineTime = $get(^rOBJ(routine,"INT"))		  			
    write routineTime'=timeStamp
}
Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:39:22 EDT
Discussion (4)3
Log in or sign up to continue

Examples:

Create a class DC.Demo.UpToDate and save/compile it.  $System.OBJ.IsUpToDate("DC.Demo.UpToDate") returns 1. Add a method with /// documentation and save but don't compile - it returns 0. Change the /// documentation for the method and save (don't compile) -  $System.OBJ.IsUpToDate("DC.Demo.UpToDate") returns 0, but $System.OBJ.IsUpToDate("DC.Demo.UpToDate",0,1) returns 1.

Create a routine named DC.Demo.UpToDate, save and compile. This returns 1:
##class(%Library.RoutineMgr).%OpenId("DC.Demo.UpToDate.MAC").UpToDate
Save and don't compile. This returns 0:

##class(%Library.RoutineMgr).%OpenId("DC.Demo.UpToDate.MAC").UpToDate

Thanks. I tried it and it works great most the time. However, I got a few cases where the IsUpToDate() returns 0 while the class does not show any "+" sign in Studio. I tried different values for "type" parameter but it does not help.

The error reported is as such : 
ERROR: ^oddCOM(cls,timechanged) does not exist

I checked and indeed there is no TimeChanged or TimeCreated in the class compiled global. Seems Studio is happy with that.