Skip to content

Commit 6e1e007

Browse files
committed
No way to create arbitrary DateTime #294
1 parent bb83bdf commit 6e1e007

4 files changed

Lines changed: 51 additions & 2 deletions

File tree

runtime/com.abstratt.mdd.runtime.core/src/com/abstratt/mdd/core/runtime/types/BasicType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static BasicType runNativeOperation(ExecutionContext context, Class<?> ja
3535
throw new ModelExecutionException("Null was dereferenced", operation, null);
3636
} catch (NoSuchMethodException e) {
3737
LogUtils.logWarning(Runtime.ID, "Method not found", e);
38-
throw new RuntimeException(e.getMessage() + "(" + StringUtils.join(arguments) + ") in " + javaClass.getName());
38+
throw new RuntimeException("Unknown method " + e.getMessage() + "(" + StringUtils.join(arguments) + ") in " + javaClass.getName());
3939
} catch (IllegalAccessException e) {
4040
throw new RuntimeException(e);
4141
}

runtime/com.abstratt.mdd.runtime.core/src/com/abstratt/mdd/core/runtime/types/DateTimeType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static DateTimeType make(@SuppressWarnings("unused") ExecutionContext con
3333
return new DateTimeType(new Date(year.primitiveValue().intValue() - 1900, month.primitiveValue().intValue() - 1, day.primitiveValue()
3434
.intValue()));
3535
}
36-
36+
3737
public static DateTimeType today(@SuppressWarnings("unused") ExecutionContext context) {
3838
Date value = new Date();
3939
value.setHours(0);

runtime/com.abstratt.mdd.runtime.core/src/com/abstratt/mdd/core/runtime/types/DateType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public static DateType fromValue(Date original) {
2828
public static DateType fromValue(LocalDate original) {
2929
return new DateType(original);
3030
}
31+
32+
public DateTimeType at(@SuppressWarnings("unused") ExecutionContext context, TimeType time) {
33+
return DateTimeType.fromValue(this.primitiveValue().atTime(time.primitiveValue()));
34+
}
35+
3136

3237
public static DateType make(@SuppressWarnings("unused") ExecutionContext context, IntegerType year, IntegerType month, IntegerType day) {
3338
return new DateType(new Date(year.primitiveValue().intValue() - 1900, month.primitiveValue().intValue() - 1, day.primitiveValue()

tests/com.abstratt.mdd.core.tests.runtime/src/com/abstratt/mdd/core/tests/runtime/RuntimeDateAndTimeTests.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.eclipse.core.runtime.CoreException;
1111

1212
import com.abstratt.mdd.core.runtime.types.BooleanType;
13+
import com.abstratt.mdd.core.runtime.types.DateTimeType;
1314
import com.abstratt.mdd.core.runtime.types.DateType;
1415
import com.abstratt.mdd.core.runtime.types.IntegerType;
1516
import com.abstratt.mdd.core.runtime.types.PrimitiveType;
@@ -254,7 +255,50 @@ public void testLiteral() throws CoreException {
254255
TestCase.assertEquals(8, created.getMonthValue());
255256
TestCase.assertEquals(30, created.getDayOfMonth());
256257
}
258+
259+
public void testMakeDateTime() throws CoreException {
260+
String model = "";
261+
model += "model tests;\n";
262+
model += "import mdd_types;\n";
263+
model += "class DateUtil\n";
264+
model += "static operation createDateTime() : DateTime;\n";
265+
model += "begin\n";
266+
model += " return Date#make(2011, 08, 30).at(Time#make(20, 15, 30, 375));\n";
267+
model += "end;\n";
268+
model += "end;\n";
269+
model += "end.";
257270

271+
parseAndCheck(model);
272+
LocalDateTime created = ((DateTimeType) runStaticOperation("tests::DateUtil", "createDateTime")).primitiveValue();
273+
TestCase.assertEquals(2011, created.getYear());
274+
TestCase.assertEquals(8 , created.getMonthValue());
275+
TestCase.assertEquals(30, created.getDayOfMonth());
276+
TestCase.assertEquals(20, created.getHour());
277+
TestCase.assertEquals(15, created.getMinute());
278+
TestCase.assertEquals(30, created.getSecond());
279+
TestCase.assertEquals(375000000, created.getNano());
280+
}
281+
282+
public void testMakeTime() throws CoreException {
283+
String model = "";
284+
model += "model tests;\n";
285+
model += "import mdd_types;\n";
286+
model += "class DateUtil\n";
287+
model += "static operation createTime() : Time;\n";
288+
model += "begin\n";
289+
model += " return Time#make(20, 15, 30, 375);\n";
290+
model += "end;\n";
291+
model += "end;\n";
292+
model += "end.";
293+
294+
parseAndCheck(model);
295+
LocalTime created = ((TimeType) runStaticOperation("tests::DateUtil", "createTime")).primitiveValue();
296+
TestCase.assertEquals(20, created.getHour());
297+
TestCase.assertEquals(15, created.getMinute());
298+
TestCase.assertEquals(30, created.getSecond());
299+
TestCase.assertEquals(375000000, created.getNano());
300+
}
301+
258302
public void testMakeDate() throws CoreException {
259303
String model = "";
260304
model += "model tests;\n";

0 commit comments

Comments
 (0)