Skip to content

Commit

Permalink
Added -Dvallang.random.partialDateTime=true option to turn off genera…
Browse files Browse the repository at this point in the history
…tion of partial datetimes by default
  • Loading branch information
jurgenvinju committed Sep 27, 2021
1 parent 6233a9a commit c88bf39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
-Xmx2G
-ea
-Dvallang.test.seed=${buildNumber}
-Dvallang.random.partialDateTime=true
</argLine>
</configuration>
</plugin>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/usethesource/vallang/type/DateTimeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ private static long between(Random r, long a, long b) {
@Override
public IValue randomValue(Random random, IValueFactory vf, TypeStore store, Map<Type, Type> typeParameters,
int maxDepth, int maxBreadth) {
boolean partialDateTime = "true".equals(System.getProperty("vallang.random.partialDateTime"));

try {
if (random.nextDouble() > 0.8) {
if (partialDateTime && random.nextDouble() > 0.8) {
LocalTime result = LocalTime.ofSecondOfDay(between(random, ChronoField.SECOND_OF_DAY));
return vf.time(
result.getHour(),
Expand All @@ -87,7 +88,7 @@ public IValue randomValue(Random random, IValueFactory vf, TypeStore store, Map<
(int) TimeUnit.MILLISECONDS.convert(result.getNano(), TimeUnit.NANOSECONDS)
);
}
if (random.nextDouble() > 0.8) {
if (partialDateTime && random.nextDouble() > 0.8) {
LocalDate result = LocalDate.ofEpochDay(between(random,
LocalDate.of(0,1, 1).toEpochDay(),
LocalDate.of(9999,1, 1).toEpochDay()
Expand Down

0 comments on commit c88bf39

Please sign in to comment.