:: time_widgets[widget]
<<widget 'addtime'>>
	<<set $time.minutes += _args[0]>>
<</widget>>

<<widget 'onceADay' container>>
	<<set $onceADayDict ??= {}>>
	<<if ($onceADayDict[_args[0]] ?? -1) < $time.daystart>>
		_contents
		<<set $onceADayDict[_args[0]] = $time.daystart>>
	<</if>>
<</widget>>

<<widget 'cooldown' container>>
	<<set $cooldownsDict ??= {}>>
	<<set _cooldownKey = _args[0]>>
	<<set _cooldownNow = $time.daystart * 1440 + $time.hour * 60 + $time.minutes>>
	<<if !setup.isOnCooldown(_cooldownKey)>>
		<<set _cooldownDurationInMinutes = _args[1] ?? 60>>
		<<set $cooldownsDict[_cooldownKey] = _cooldownNow + _cooldownDurationInMinutes>>
		_contents
	<</if>>
<</widget>>

:: time_scripts[script]
	setup.isOnCooldown ??= function(cooldownId){
		const gtime = State.variables.time;
		const cooldownsDict = State.variables.cooldownsDict ?? {};
		const cooldownExisting = cooldownsDict[cooldownId] ?? 0;
		const cooldownNow = gtime.daystart * 1440 + gtime.hour * 60 + gtime.minutes;
		if(cooldownNow >= cooldownExisting)
			return false;
		return true;
	}