Skip to content

Commit

Permalink
Enable property to switch off random zone offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Sep 27, 2021
1 parent c88bf39 commit 4ea872a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
-ea
-Dvallang.test.seed=${buildNumber}
-Dvallang.random.partialDateTime=true
-Dvallang.random.zoneOffsets=true
</argLine>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public IString format(String format) {
}

private static long currentTotalOffset() {
// subjectief?
return OffsetDateTime.now().getOffset().getTotalSeconds();
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/usethesource/vallang/type/DateTimeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private static long between(Random r, long a, long b) {
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"));
boolean zoneOffsets = "true".equals(System.getProperty("vallang.random.zoneOffsets"));

try {
if (partialDateTime && random.nextDouble() > 0.8) {
Expand Down Expand Up @@ -104,7 +105,7 @@ public IValue randomValue(Random random, IValueFactory vf, TypeStore store, Map<
Instant.now().getEpochSecond() + TimeUnit.DAYS.toSeconds(700)
), 0
);
if (random.nextDouble() > 0.5) {
if (!zoneOffsets || random.nextDouble() > 0.5) {
return vf.datetime(result.toEpochMilli());
}
ZoneOffset off = ZoneOffset.ofTotalSeconds((int)between(random, ChronoField.OFFSET_SECONDS));
Expand Down

0 comments on commit 4ea872a

Please sign in to comment.