Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
fc8d39d
Add time utilities
beutlich Dec 2, 2019
ea712df
Add leap year utility functions
beutlich Dec 2, 2019
94d73b8
Rename TimeType components
beutlich Dec 5, 2019
24da25c
Add day of week computation
beutlich Dec 6, 2019
cf47cd2
Let dayOfWeek return Integer in range [1, 7]
beutlich Dec 10, 2019
6203479
Add function to round to nearest integer
m-kessler Apr 8, 2020
315491a
Add arrays for month and day names (full and abbreviated)
m-kessler Apr 9, 2020
63a192d
Integrate DateTime record from Testing lib
m-kessler Apr 7, 2020
364d423
Integrate Duration record from Testing lib
m-kessler Apr 7, 2020
ac5f1c5
Rename variables in DateTime (s -> second, ...)
m-kessler Apr 8, 2020
42eacfc
Rename seconds to totalSeconds in Duration
m-kessler Apr 8, 2020
de0086f
Rename variables in Duration (s -> seconds, ...)
m-kessler Apr 8, 2020
a83959c
Support '-' for DateTime
m-kessler Apr 8, 2020
bf2c90f
Add DateTime.now()
m-kessler Apr 9, 2020
5606352
Add tests for Duration
m-kessler Apr 8, 2020
2e5e660
Add tests for DateTime
m-kessler Apr 8, 2020
f642aca
Format DateTime like strftime in C++ and Python
m-kessler Apr 9, 2020
fd62fde
Align string formatting for Duration with DateTime
m-kessler Apr 9, 2020
344c3af
Add class comments to DateTime and all its operators
m-kessler Apr 9, 2020
13cd2f2
Add class comments to Duration and all its operators
m-kessler Apr 9, 2020
d880a3b
Use dt as variable name for DateTimes
m-kessler Apr 9, 2020
ab50168
Use d as variable name for Durations
m-kessler Apr 9, 2020
cd88ed3
Add basic doc for DateTime
m-kessler Apr 9, 2020
ccfad24
Add basic doc for Duration
m-kessler Apr 9, 2020
01f93a3
Fix lookup of package constant
beutlich Apr 9, 2020
d48e736
Fix HTML tags and double quotes
beutlich Apr 9, 2020
0537a1e
Can use Modelica.Math.nearestInteger
beutlich Apr 10, 2020
d1bec22
Remove TimeType in favor of DateTime
beutlich Apr 10, 2020
3c790a9
Fix icon inheritance
beutlich Apr 10, 2020
4743099
Rewrite using external functions from ModelicaTime.c
beutlich Apr 11, 2020
804f8af
Reintroduce handling of milliseconds
beutlich Apr 13, 2020
dbae848
Utilize locale-independent string conversion
beutlich Apr 13, 2020
42e2088
Fix C++ compilation
beutlich Apr 13, 2020
d82669b
Update UsersGuide and package doc
beutlich Apr 13, 2020
5fa6b24
Add wrappers for external functions
beutlich Apr 13, 2020
1dc5953
Use horizontal ellipsis
beutlich Apr 13, 2020
17b705a
Avoid limitation of Duration.'String'.formatted
beutlich Apr 13, 2020
ba8b739
Fix example for string formatting of Duration
m-kessler Apr 14, 2020
c14a3b2
Make Duration constructors unambiguous
m-kessler Apr 14, 2020
a4bec5b
Fix more corner cases of ModelicaTime_difftime
beutlich Apr 14, 2020
9126bb6
Fix consideration of DST
beutlich Apr 14, 2020
8f42a6e
Fix corner case
beutlich Apr 15, 2020
5f8bc94
Fix subtraction test of DateTime
m-kessler Apr 15, 2020
883f562
Add tests for nearestInteger
m-kessler Apr 15, 2020
f2d2c25
Fix naming in nearestInteger tests
m-kessler Apr 15, 2020
2ac26fe
Implement test for Duration.'0'
beutlich Apr 15, 2020
f6c4228
Fix ModelicaTest.Utilities.Time
beutlich Apr 15, 2020
48cc424
Fix Duration.'constructor'.fromDateTimes for negative time span
beutlich Apr 17, 2020
9b2ef6d
Add another test for negative durations
m-kessler Apr 20, 2020
9ad7518
Support + and - for DateTime with Duration
m-kessler Apr 20, 2020
6159dc2
Optionally skip DateTime tests for years before 1970
m-kessler Apr 20, 2020
124c869
Use class for operator record icon
m-kessler May 19, 2020
cd033a0
Use proper comments for operators
m-kessler May 20, 2020
05f07b7
Update description
beutlich Oct 27, 2020
934ff48
Remove C99 standard version specifier
beutlich Oct 27, 2020
2d68cf3
Remove documentation of border cases
beutlich Oct 29, 2020
330f13e
Improve return value handling of localtime
beutlich Oct 29, 2020
352ee3e
Exclude past tests
beutlich Oct 29, 2020
d50f7e1
Add some tests for CI
beutlich Oct 29, 2020
d58a647
Migrate conversion to next major version
beutlich Jan 18, 2021
15d3fc8
Move third-party license files
beutlich Oct 27, 2024
0a601fa
Update CMake configuration
beutlich Oct 27, 2024
8310f9a
Fix build errors
beutlich Oct 27, 2024
5b279a0
Bump copyright year
beutlich Oct 27, 2024
677a62b
Add include guards
beutlich Oct 27, 2024
6327d64
Update include annotations
beutlich Oct 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .CI/Test/ModelicaTime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "../../Modelica/Resources/C-Sources/ModelicaTime.h"
#include "Common.c"

#include <assert.h>
#include <string.h>

int main(int argc, char **argv) {
int ms = 501;
int sec = 30;
int min = 44;
int hour = 20;
int mday = 29;
int mon = 10;
int year = 2020;
const char *format = "%Y-%m-%d %H:%M:%S.%L";
int maxSize = 128;
const char *dateStr = ModelicaTime_strftime(ms, sec, min, hour, mday, mon, year, format, maxSize);
ModelicaFormatMessage("Date: %s\n", dateStr);
assert(0 == strcmp("2020-10-29 20:44:30.501", dateStr));
ModelicaTime_strptime(&ms, &sec, &min, &hour, &mday, &mon, &year, "2000-09-30 06:45:01.123", format);
assert(ms == 123);
assert(sec == 1);
assert(min == 45);
assert(hour == 6);
assert(mday == 30);
assert(mon == 9);
assert(year == 2000);
return 0;
}
4 changes: 4 additions & 0 deletions .CI/Test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if test ! "$1" = "nostatic"; then
./a.out || exit 1
"$CC" -L $LIBRARIES ModelicaStrings.c -Wl,-Bstatic -lModelicaExternalC -Wl,-Bdynamic || exit 1
./a.out || exit 1
"$CC" -L $LIBRARIES ModelicaTime.c -Wl,-Bstatic -lModelicaExternalC -Wl,-Bdynamic || exit 1
./a.out || exit 1
"$CC" -L $LIBRARIES Streams.c -Wl,-Bstatic -lModelicaExternalC -Wl,-Bdynamic || exit 1
./a.out || exit 1
"$CC" -L $LIBRARIES Tables.c -Wl,-Bstatic -lModelicaStandardTables -lModelicaIO -lModelicaMatIO -lzlib -Wl,-Bdynamic -lm || exit 1
Expand All @@ -31,6 +33,8 @@ if test ! "$1" = "onlystatic"; then
./a.out || exit 1
"$CC" -L $LIBRARIES -Wl,-rpath $LIBRARIES ModelicaStrings.c -lModelicaExternalC || exit 1
./a.out || exit 1
"$CC" -L $LIBRARIES -Wl,-rpath $LIBRARIES ModelicaTime.c -lModelicaExternalC || exit 1
./a.out || exit 1
"$CC" -L $LIBRARIES -Wl,-rpath $LIBRARIES Streams.c -lModelicaExternalC || exit 1
./a.out || exit 1
"$CC" -L $LIBRARIES -Wl,-rpath $LIBRARIES Tables.c -lModelicaStandardTables -lModelicaIO -lModelicaMatIO || exit 1
Expand Down
13 changes: 10 additions & 3 deletions Complex.mo
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ operator record Complex "Complex number with overloaded operators"
end fromReal;
annotation (Documentation(info="<html>
<p>Here the constructor operator(s) is/are defined.</p>
</html>"), Icon(graphics={Rectangle(
</html>"), Icon(
graphics={
Rectangle(
lineColor={200,200,200},
fillColor={248,248,248},
fillPattern=FillPattern.HorizontalCylinder,
extent={{-100,-100},{100,100}},
radius=25.0), Rectangle(
radius=25.0),
Rectangle(
lineColor={128,128,128},
extent={{-100,-100},{100,100}},
radius=25.0)}));
radius=25.0),
Text(
textColor={128,128,128},
extent={{-90,-90},{90,90}},
textString="f")}));
end 'constructor';

encapsulated operator function '0' "Zero-element of addition (= Complex(0))"
Expand Down
8 changes: 4 additions & 4 deletions Modelica/Blocks/Math.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ Otherwise the input angle <code>u</code> is wrapped to the <a href=\"https://en.
Interfaces.IntegerOutput y "Connector of Integer output signal" annotation (
Placement(transformation(extent={{100,-10},{120,10}})));
equation
y = if (u > 0) then integer(floor(u + 0.5)) else integer(ceil(u - 0.5));
y = Modelica.Math.nearestInteger(u);
annotation (Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100.0,-100.0},{100.0,100.0}}), graphics={
Expand All @@ -1959,11 +1959,11 @@ Otherwise the input angle <code>u</code> is wrapped to the <a href=\"https://en.
30.0,-10.0},{30.0,-20.0},{50.0,0.0}})}), Documentation(info="<html>
<p>
This block computes the output <strong>y</strong>
as <em>nearest integer value</em> of the input <strong>u</strong>:
as <em>nearest integer value</em> of the input <strong>u</strong> utilizing the
function <a href=\"modelica://Modelica.Math.nearestInteger\">nearestInteger</a>:
</p>
<blockquote><pre>
y = <strong>integer</strong>( <strong>floor</strong>( u + 0.5 ) ) for u &gt; 0;
y = <strong>integer</strong>( <strong>ceil </strong>( u - 0.5 ) ) for u &lt; 0;
y = Modelica.Math.<strong>nearestInteger</strong>(u);
</pre></blockquote>
</html>"));
end RealToInteger;
Expand Down
47 changes: 39 additions & 8 deletions Modelica/Icons.mo
Original file line number Diff line number Diff line change
Expand Up @@ -527,29 +527,60 @@ This icon is designed for a <strong>translational sensor</strong> model.
extent={{-150,60},{150,100}},
textString="%name"),
Rectangle(
origin={0.0,-25.0},
origin={0,-25},
lineColor={64,64,64},
fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-100.0,-75.0},{100.0,75.0}},
radius=25.0),
extent={{-100,-75},{100,75}},
radius=25),
Line(
points={{-100.0,0.0},{100.0,0.0}},
points={{-100,0},{100,0}},
color={64,64,64}),
Line(
origin={0.0,-50.0},
points={{-100.0,0.0},{100.0,0.0}},
origin={0,-50},
points={{-100,0},{100,0}},
color={64,64,64}),
Line(
origin={0.0,-25.0},
points={{0.0,75.0},{0.0,-75.0}},
origin={0,-25},
points={{0,75},{0,-75}},
color={64,64,64})}), Documentation(info="<html>
<p>
This icon is indicates a record.
</p>
</html>"));
end Record;

partial class OperatorRecord "Icon for operator records"

annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,100}}), graphics={
Text(
textColor={0,0,255},
extent={{-150,60},{150,100}},
textString="%name"),
Rectangle(
origin={0,-25},
lineColor={64,64,64},
fillColor={255,215,136},
fillPattern=FillPattern.Solid,
extent={{-100,-75},{100,75}},
radius=25),
Line(
points={{-100,0},{100,0}},
color={64,64,64}),
Line(
origin={0,-50},
points={{-100,0},{100,0}},
color={64,64,64}),
Line(
origin={0,-25},
points={{0,75},{0,-75}},
color={64,64,64})}), Documentation(info="<html>
<p>
This icon is indicates an operator record.
</p>
</html>"));
end OperatorRecord;

type TypeReal "Icon for Real types"
extends Real;
annotation(Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,100}}), graphics={
Expand Down
44 changes: 44 additions & 0 deletions Modelica/Math/nearestInteger.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
within Modelica.Math;
function nearestInteger "Convert real number to nearest integer value"
extends Modelica.Icons.Function;

input Real r "Real number to convert to integer";
output Integer i "Integer value, which is closest to the given real number";

algorithm
i :=if (r > 0) then integer(floor(r + 0.5)) else integer(ceil(r - 0.5));

annotation (Documentation(info="<html>

<h4>Syntax</h4>
<blockquote><pre>
Math.<strong>nearestInteger</strong>(r);
</pre></blockquote>

<h4>Description</h4>
<p>
The input value \"r\" of type Real is converted to the closest Integer value \"i\",
using the <em>round half away from zero</em> rule with the equation:
</p>
<blockquote><pre>
i = <strong>integer</strong>( <strong>floor</strong>( r + 0.5 ) ) for r &gt; 0;
i = <strong>integer</strong>( <strong>ceil</strong>( r - 0.5 ) ) for r &lt; 0;
</pre></blockquote>

<h4>Example</h4>
<blockquote><pre>
import Modelica.Math;
Math.nearestInteger(0.4); // = 0
Math.nearestInteger(0.5); // = 1
Math.nearestInteger(-0.4); // = 0
Math.nearestInteger(-0.5); // = -1
</pre></blockquote>

<h4>Note</h4>

<p>
This function does the same conversion as the block
<a href=\"modelica://Modelica.Blocks.Math.RealToInteger\">RealToInteger</a>.
</p>
</html>"));
end nearestInteger;
1 change: 1 addition & 0 deletions Modelica/Math/package.order
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ FastFourierTransform
Icons
isEqual
isPowerOf2
nearestInteger
sin
cos
tan
Expand Down
4 changes: 4 additions & 0 deletions Modelica/Resources/BuildProjects/CMake/src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ set(EXTC_SOURCES
"${MODELICA_SOURCE_DIR}/ModelicaRandom.h"
"${MODELICA_SOURCE_DIR}/ModelicaStrings.c"
"${MODELICA_SOURCE_DIR}/ModelicaStrings.h"
"${MODELICA_SOURCE_DIR}/ModelicaTime.c"
"${MODELICA_SOURCE_DIR}/ModelicaTime.h"
"${MODELICA_SOURCE_DIR}/g2constructor.h"
"${MODELICA_SOURCE_DIR}/repl_str.h"
"${MODELICA_SOURCE_DIR}/stdint_msvc.h"
"${MODELICA_SOURCE_DIR}/stdint_wrap.h"
"${MODELICA_SOURCE_DIR}/strptime.h"
"${MODELICA_SOURCE_DIR}/uthash.h"
"${MODELICA_SOURCE_DIR}/win32_dirent.c"
"${MODELICA_SOURCE_DIR}/win32_dirent.h"
Expand Down
1 change: 1 addition & 0 deletions Modelica/Resources/BuildProjects/CMake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if(MODELICA_BUILD_TESTING)
set(MODELICA_TESTS
FileSystem
ModelicaStrings
ModelicaTime
Streams
Tables
TablesFromCsvFile
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Resources/BuildProjects/autotools/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lib_LTLIBRARIES = libzlib.la libModelicaExternalC.la libModelicaMatIO.la libModelicaIO.la libModelicaStandardTables.la
libModelicaExternalC_la_SOURCES = ../../C-Sources/ModelicaFFT.c ../../C-Sources/ModelicaInternal.c ../../C-Sources/ModelicaRandom.c ../../C-Sources/ModelicaStrings.c
libModelicaExternalC_la_SOURCES = ../../C-Sources/ModelicaFFT.c ../../C-Sources/ModelicaInternal.c ../../C-Sources/ModelicaRandom.c ../../C-Sources/ModelicaStrings.c ../../C-Sources/ModelicaTime.c
libModelicaExternalC_la_LIBADD = @LIBMATH@
libModelicaIO_la_SOURCES = ../../C-Sources/ModelicaIO.c
libModelicaIO_la_LIBADD = libModelicaMatIO.la
Expand Down
6 changes: 5 additions & 1 deletion Modelica/Resources/BuildProjects/gcc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ EXTC_OBJS = \
ModelicaFFT.o \
ModelicaInternal.o \
ModelicaRandom.o \
ModelicaStrings.o
ModelicaStrings.o \
ModelicaTime.o

TABLES_OBJS = \
ModelicaStandardTables.o \
Expand Down Expand Up @@ -93,6 +94,9 @@ ModelicaRandom.o: ../../C-Sources/ModelicaRandom.c
ModelicaStrings.o: ../../C-Sources/ModelicaStrings.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(INC) -c -o $@ $<

ModelicaTime.o: ../../C-Sources/ModelicaTime.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(INC) -c -o $@ $<

%.o: ../../C-Sources/zlib/%.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(INC) -c -o $@ $<

Expand Down
Loading
Loading