This appears to be how nUI does it and I haven't seen it be too far out with its calculations
Lua Code:
for i=1,40 do
local aura.name, aura.icon, aura.count, aura.type, aura.max_time, aura.end_time, aura.caster, aura.is_stealable = UnitAura( unit_id, i, filter );
if aura.max_time and aura.max_time > 0 then
aura.start_time = aura.end_time - aura.max_time;
elseif aura.end_time and aura.end_time > 0 then
aura.start_time = GetTime();
aura.max_time = aura.end_time - aura.start_time;
else
aura.max_time = nil;
aura.start_time = nil;
aura.end_time = nil;
end
end
nUI calls the function that contains this code using a function ( updateAuraInfo( unit_id, unit_info ) ) for each unit. Which is called whenever the custom OnAuraUpdate function is run every update cycle and there is something to process in its UpdateQueue.
Our OnAuraEvent function handles the following events:
frame:RegisterEvent( "ADDON_LOADED" );
frame:RegisterEvent( "PLAYER_ENTERING_WORLD" );
frame:RegisterEvent( "UNIT_AURA" );
In ADDON_LOADED we set up the aura buttons and refresh the callbacks ( which then updates the auras )
In PLAYER_ENTERING_WORLD we refresh the callbacks again
In UNIT_AURA we add the aura and unit it has affected to an update queue to be acted on the next time the game does an update cycle.
I haven't played with C_Timer myself so not sure what restrictions if any there are in how it can be used but in *theory* you could do something like the following but I suspect it would just set up multiple timers, so you may have to have some sort of list of timers and whether they can be re-used:
Lua Code:
for i=1,40 do
local name, icon, count, type, maxTime, endTime, caster, isStealable = UnitAura( unit_id, i, filter );
if name then
local startTime = GetTime();
local timeLeft = endTime - startTime
local timeBufferImminent = 10
local timeBufferSoon = 60
C_Timer.After(timeLeft - timeBufferImminent,function() AuraExpireImminent(unit_id,name,i) end)
C_Timer.After(timeLeft - timeBufferSoon,function() AuraExpireSoon(unit_id, name,i) end)
end
end
I've added name in there in case there is a glitch and aura i is no longer aura name. How that would occur I don't know. How much of the aura system is accessible I don't know myself either. I recall limits on only seeing your own auras on other players or npcs. But not sure if that was Classic or Retail.