I am on Windows 10 Pro (64 Bit) Version 10.0.17134 Build 17134
I tried this again:
package TestingTime "Testing Operator Record"
operator record Time
Integer s "Second";
encapsulated operator 'constructor'
import Time;
function from_s
input Integer s "Seconds";
output Time t(s=s);
algorithm
end from_s;
function from_d
input Integer d "Days";
output Time t(s=d*24*3600);
algorithm
end from_d;
end 'constructor';
encapsulated operator 'String' "Convert Time to string"
import Time;
function formated
input Time t;
input String format = "s" annotation(choices(choice="s" "seconds", choice="d" "days"));
output String str;
algorithm
if format == "d" then
str :=String(t.s/24/3600);
else
str :=String(t.s);
end if;
end formated;
end 'String';
encapsulated operator function '==' "Compare time records"
import Time;
input Time t1;
input Time t2;
output Boolean result "= t1 == t2";
algorithm
result := t1.s == t2.s;
end '==';
end Time;
model TestTime
Time d1 = Time(d=1);
Time d2 = Time(d=2);
equation
Modelica.Utilities.Streams.print(String(d1, format="s"));
Modelica.Utilities.Streams.print(String(d2, format="s"));
end TestTime;
//dropping annotations for readability...
end TestingTime;
And validating this package leads to:
Error: Error occurred while flattening model TestingTime.TestTime
Error: [<interactive>:0:0-0:0] Only classes of type 'operator record' may contain elements of type 'operator function'; '==' was found in a class that has restriction 'operator record'.
Error: [<interactive>:41:5-41:18] Class Time not found in scope TestingTime.Time.'=='.
Error: [<interactive>:26:7-26:19] Class Time not found in scope TestingTime.Time.'String'.formated.
Error: [<interactive>:17:7-17:33] Class Time not found in scope TestingTime.Time.'constructor'.from_d.
Error: [<interactive>:11:7-11:25] Class Time not found in scope TestingTime.Time.'constructor'.from_s.
Error: Error occurred while flattening model TestingTime.Time
Error: [<interactive>:0:0-0:0] Only classes of type 'operator record' may contain elements of type 'operator function'; '==' was found in a class that has restriction 'operator record'.
Error: [<interactive>:41:5-41:18] Class Time not found in scope TestingTime.Time.'=='.
Error: [<interactive>:26:7-26:19] Class Time not found in scope TestingTime.Time.'String'.formated.
Error: [<interactive>:17:7-17:33] Class Time not found in scope TestingTime.Time.'constructor'.from_d.
Error: [<interactive>:11:7-11:25] Class Time not found in scope TestingTime.Time.'constructor'.from_s.
Check failed for model: TestingTime.Time.
Check failed for model: TestingTime.TestTime.
Validation of package TestingTime completed with errors.