diff --git a/Modelica/Utilities/Internal.mo b/Modelica/Utilities/Internal.mo index c1ecfd3060..f2948e690c 100644 --- a/Modelica/Utilities/Internal.mo +++ b/Modelica/Utilities/Internal.mo @@ -243,6 +243,25 @@ end FileSystem; package Time "Internal package with external functions as interface to date and time" extends Modelica.Icons.InternalPackage; + + pure function diffTime "Convert local time to elapsed seconds since custom epoch year" + extends Modelica.Icons.Function; + input Integer ms "Millisecond"; + input Integer sec "Second"; + input Integer min "Minute"; + input Integer hour "Hour"; + input Integer day "Day"; + input Integer mon "Month"; + input Integer year "Year"; + input Integer epoch_year = 1970 "Reference year"; + output Real seconds "Elapsed seconds since epoch_year in the current time zone"; + external "C" seconds = ModelicaTime_difftime(ms, sec, min, hour, day, mon, year, epoch_year) + annotation (IncludeDirectory="modelica://Modelica/Resources/C-Sources", Include="#include \"ModelicaTime.c\""); + annotation (Documentation(info=" +TODO +")); + end diffTime; + impure function getTime "Retrieve the local time (in the local time zone)" extends Modelica.Icons.Function; output Integer ms "Millisecond"; @@ -342,7 +361,7 @@ TODO pure function stringToTime "Retrieve the local time (in the local time zone) from formatted string" extends Modelica.Icons.Function; - input String str "Formatted data and time string"; + input String str "Formatted date and time string"; input String format = "%Y-%m-%d %H:%M:%S" "Format string passed to strptime"; output Integer ms "Millisecond"; output Integer sec "Second"; @@ -358,12 +377,31 @@ TODO ")); end stringToTime; + pure function timeToString "Convert the local time (in the local time zone) to string" + extends Modelica.Icons.Function; + input Integer ms "Millisecond"; + input Integer sec "Second"; + input Integer min "Minute"; + input Integer hour "Hour"; + input Integer day "Day"; + input Integer mon "Month"; + input Integer year "Year"; + input String format = "%Y-%m-%d %H:%M:%S" "Format string passed to strftime"; + input Integer maxSize = 128 "Maximal length of formatted string"; + output String str "Formatted date and time string"; + external "C99" str = ModelicaTime_strftime(ms, sec, min, hour, day, mon, year, format, maxSize) + annotation (IncludeDirectory="modelica://Modelica/Resources/C-Sources", Include="#include \"ModelicaTime.c\""); + annotation (Documentation(info=" +TODO +")); + end timeToString; + function dayOfWeek "Return day of week for given date" extends Modelica.Icons.Function; input Integer year "Year"; input Integer mon=1 "Month"; input Integer day=1 "Day of month"; - output Integer dow(min=1, max=7) "Day of week: 1 = Monday, ..., 6 = Saturday, 7 = Sunday"; + output Integer dow(min=1, max=7) "Day of week: 1 = Monday, ..., 6 = Saturday, 7 = Sunday"; protected constant Integer t[:] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; Integer y = year; diff --git a/Modelica/Utilities/Time.mo b/Modelica/Utilities/Time.mo index f3432cf491..4175ee15d7 100644 --- a/Modelica/Utilities/Time.mo +++ b/Modelica/Utilities/Time.mo @@ -247,7 +247,7 @@ days = leapDays(2000, 2020) // = 5 leap days in range [2000, 2019] import Modelica.Utilities.Internal.Time.stringToTime; extends Function; - input String str "Formatted data and time string"; + input String str "Formatted date and time string"; input String format = "%Y-%m-%d %H:%M:%S" "Format string passed to strptime"; output DateTime dt "Date and time"; @@ -290,16 +290,18 @@ days = leapDays(2000, 2020) // = 5 leap days in range [2000, 2019] import Modelica.Utilities.Time.DateTime; import Modelica.Icons.Function; - pure function formatted "Use strftime conversion to format a DateTime record as string" + function formatted "Use strftime conversion to format a DateTime record as string" + import Modelica.Utilities.Internal.Time.timeToString; extends Function; input DateTime dt "Date and time"; input String format = "%Y-%m-%d %H:%M:%S" "Format string passed to strftime"; input Integer maxSize = 128 "Maximal length of formatted string"; - output String str "Formatted data and time string"; - external "C99" str = ModelicaTime_strftime(dt.millisecond, dt.second, dt.minute, dt.hour, dt.day, dt.month, dt.year, format, maxSize) - annotation (IncludeDirectory="modelica://Modelica/Resources/C-Sources", Include="#include \"ModelicaTime.c\""); - annotation (Documentation(info=" + output String str "Formatted date and time string"; + + algorithm + str := timeToString(dt.millisecond, dt.second, dt.minute, dt.hour, dt.day, dt.month, dt.year, format, maxSize); + annotation (Inline=true, Documentation(info="

Syntax

@@ -584,8 +586,9 @@ String(dt, format=\"%A, %d. %B %y, %H:%M:%S.%L\")  // = \"Thursday, 24. December
             points={{-50,0},{50,0}})}));
     end '-';
 
-    encapsulated pure function epoch "Convert DateTime to elapsed seconds since custom epoch year"
+    encapsulated function epoch "Convert DateTime to elapsed seconds since custom epoch year"
       import Modelica.Utilities.Time.DateTime;
+      import Modelica.Utilities.Internal.Time.diffTime;
       import Modelica.Icons.Function;
       extends Function;
 
@@ -593,8 +596,9 @@ String(dt, format=\"%A, %d. %B %y, %H:%M:%S.%L\")  // = \"Thursday, 24. December
       input Integer epoch_year = 1970 "Reference year";
       output Real seconds "Elapsed seconds since epoch_year in the current time zone";
 
-      external "C" seconds = ModelicaTime_difftime(dt.millisecond, dt.second, dt.minute, dt.hour, dt.day, dt.month, dt.year, epoch_year)
-        annotation (IncludeDirectory="modelica://Modelica/Resources/C-Sources", Include="#include \"ModelicaTime.c\"");
+    algorithm
+      seconds := diffTime(dt.millisecond, dt.second, dt.minute, dt.hour, dt.day, dt.month, dt.year, epoch_year);
+      annotation (Inline=true);
     end epoch;
 
     encapsulated function now "Get current system date and time as DateTime"
@@ -604,7 +608,8 @@ String(dt, format=\"%A, %d. %B %y, %H:%M:%S.%L\")  // = \"Thursday, 24. December
 
       output DateTime now "Current date and time";
     algorithm
-       now := DateTime.'constructor'.fromSystemTime();
+      now := DateTime.'constructor'.fromSystemTime();
+      annotation (Inline=true);
     end now;
 
     annotation (Documentation(info="