Skip to content

Commit

Permalink
No way to create arbitrary DateTime #294
Browse files Browse the repository at this point in the history
  • Loading branch information
abstratt committed Oct 14, 2021
1 parent bb83bdf commit 6e1e007
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static BasicType runNativeOperation(ExecutionContext context, Class<?> ja
throw new ModelExecutionException("Null was dereferenced", operation, null);
} catch (NoSuchMethodException e) {
LogUtils.logWarning(Runtime.ID, "Method not found", e);
throw new RuntimeException(e.getMessage() + "(" + StringUtils.join(arguments) + ") in " + javaClass.getName());
throw new RuntimeException("Unknown method " + e.getMessage() + "(" + StringUtils.join(arguments) + ") in " + javaClass.getName());
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static DateTimeType make(@SuppressWarnings("unused") ExecutionContext con
return new DateTimeType(new Date(year.primitiveValue().intValue() - 1900, month.primitiveValue().intValue() - 1, day.primitiveValue()
.intValue()));
}

public static DateTimeType today(@SuppressWarnings("unused") ExecutionContext context) {
Date value = new Date();
value.setHours(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public static DateType fromValue(Date original) {
public static DateType fromValue(LocalDate original) {
return new DateType(original);
}

public DateTimeType at(@SuppressWarnings("unused") ExecutionContext context, TimeType time) {
return DateTimeType.fromValue(this.primitiveValue().atTime(time.primitiveValue()));
}


public static DateType make(@SuppressWarnings("unused") ExecutionContext context, IntegerType year, IntegerType month, IntegerType day) {
return new DateType(new Date(year.primitiveValue().intValue() - 1900, month.primitiveValue().intValue() - 1, day.primitiveValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.eclipse.core.runtime.CoreException;

import com.abstratt.mdd.core.runtime.types.BooleanType;
import com.abstratt.mdd.core.runtime.types.DateTimeType;
import com.abstratt.mdd.core.runtime.types.DateType;
import com.abstratt.mdd.core.runtime.types.IntegerType;
import com.abstratt.mdd.core.runtime.types.PrimitiveType;
Expand Down Expand Up @@ -254,7 +255,50 @@ public void testLiteral() throws CoreException {
TestCase.assertEquals(8, created.getMonthValue());
TestCase.assertEquals(30, created.getDayOfMonth());
}

public void testMakeDateTime() throws CoreException {
String model = "";
model += "model tests;\n";
model += "import mdd_types;\n";
model += "class DateUtil\n";
model += "static operation createDateTime() : DateTime;\n";
model += "begin\n";
model += " return Date#make(2011, 08, 30).at(Time#make(20, 15, 30, 375));\n";
model += "end;\n";
model += "end;\n";
model += "end.";

parseAndCheck(model);
LocalDateTime created = ((DateTimeType) runStaticOperation("tests::DateUtil", "createDateTime")).primitiveValue();
TestCase.assertEquals(2011, created.getYear());
TestCase.assertEquals(8 , created.getMonthValue());
TestCase.assertEquals(30, created.getDayOfMonth());
TestCase.assertEquals(20, created.getHour());
TestCase.assertEquals(15, created.getMinute());
TestCase.assertEquals(30, created.getSecond());
TestCase.assertEquals(375000000, created.getNano());
}

public void testMakeTime() throws CoreException {
String model = "";
model += "model tests;\n";
model += "import mdd_types;\n";
model += "class DateUtil\n";
model += "static operation createTime() : Time;\n";
model += "begin\n";
model += " return Time#make(20, 15, 30, 375);\n";
model += "end;\n";
model += "end;\n";
model += "end.";

parseAndCheck(model);
LocalTime created = ((TimeType) runStaticOperation("tests::DateUtil", "createTime")).primitiveValue();
TestCase.assertEquals(20, created.getHour());
TestCase.assertEquals(15, created.getMinute());
TestCase.assertEquals(30, created.getSecond());
TestCase.assertEquals(375000000, created.getNano());
}

public void testMakeDate() throws CoreException {
String model = "";
model += "model tests;\n";
Expand Down

0 comments on commit 6e1e007

Please sign in to comment.