FUNCTION_BLOCK "SecToTime"
{ S7_Optimized_Access := 'FALSE' }
VERSION : 0.1
VAR_INPUT
dwSeconds : DWord;
END_VAR
VAR_OUTPUT
years : DInt;
days : DInt;
hours : DInt;
minutes : DInt;
seconds : DInt;
END_VAR
VAR
statValue : DInt;
END_VAR
VAR_TEMP
tempSec : DInt;
END_VAR
BEGIN
//Dieses Programm enthält einen Zeitwandler, der einen Sekundenwert in Jahre, Tage, Stunden, Minuten und Sekunden umwandelt.
//This program consists a time converter, that converts a value of seconds into years, days, hours, minutes and seconds.
//
//Der Eingabewert (in Sekunden) wird in die statische Variable statValue übertragen.
//The input value (in seconds) will transfer in the static variable statValue.
#statValue := DWORD_TO_DINT(#dwSeconds);
//Initialisierung / Initialization
#years := 0;
#days := 0;
#hours := 0;
#minutes := 0;
#seconds := 0;
//Berechne die Jahre, 1 Jahr = 31536000s
//Calculate the Years, 1 Year = 31536000s.
#years := #statValue / 31536000;
IF #years > 0 THEN
#statValue := #statValue MOD (31536000 * #years);
END_IF;
//Berechne die Tage, 1 Tag = 86400s
//Calculate the days, 1 day = 86400s.
#days := #statValue / 86400;
IF #days > 0 THEN
#statValue := #statValue MOD (86400 * #days);
END_IF;
//Berechne die Stunden, 1 Stunde = 3600s.
//Calculate the hours, 1 hour = 3600s.
#hours := #statValue / 3600;
IF #hours > 0 THEN
#statValue := #statValue MOD (3600* #hours);
END_IF;
//Berechne die Minuten, 1 Minute = 60s.
//Calculate the minutes, 1 minute = 60s.
#minutes := #statValue / 60;
IF #minutes > 0 THEN
#statValue := #statValue MOD (60* #minutes);
END_IF;
//Berechne die Sekunden, 1 Sekunde = 1s.
//Calculate the seconds, 1 second = 1s.
IF #statValue < 60 THEN
#seconds := #statValue;
END_IF;
END_FUNCTION_BLOCK