Skip to content

Commit b1da093

Browse files
Using periods in relative timeframes will now work properly
1 parent 9678522 commit b1da093

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@
5252
### Bug fixes
5353

5454
- Creating an empty DQL variable using the `$type: dql` syntax will now create a multiline comment instead of causing an
55-
error
55+
error.
5656
- When modifying or deleting a Dynatrace tenant that was already used, files using it will require the user to select
5757
a new tenant.
58+
- Using periods (`-1y` for years, `-1q` for quarters, or `-1w` for weeks) in relative timeframes will now work properly.
5859

5960
## [1.4.0] - 2026-01-28
6061

src/main/java/pl/thedeem/intellij/dql/definition/model/DQLDurationType.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import java.time.Duration;
66
import java.time.Instant;
7-
import java.time.Period;
7+
import java.time.ZoneOffset;
8+
import java.time.ZonedDateTime;
89
import java.util.Arrays;
910
import java.util.Set;
1011
import java.util.stream.Collectors;
@@ -53,10 +54,18 @@ public Instant getInstant(int duration, @NotNull Instant base) {
5354
case MINUTE -> base.plus(Duration.ofMinutes(duration));
5455
case HOUR -> base.plus(Duration.ofHours(duration));
5556
case DAY -> base.plus(Duration.ofDays(duration));
56-
case WEEK -> base.plus(Period.ofWeeks(duration));
57-
case MONTH -> base.plus(Period.ofMonths(duration));
58-
case QUARTER -> base.plus(Period.ofMonths(duration * 4));
59-
case YEAR -> base.plus(Period.ofYears(duration));
57+
case WEEK -> ZonedDateTime.ofInstant(base, ZoneOffset.UTC)
58+
.plusWeeks(duration)
59+
.toInstant();
60+
case MONTH -> ZonedDateTime.ofInstant(base, ZoneOffset.UTC)
61+
.plusMonths(duration)
62+
.toInstant();
63+
case QUARTER -> ZonedDateTime.ofInstant(base, ZoneOffset.UTC)
64+
.plusMonths(duration * 3L)
65+
.toInstant();
66+
case YEAR -> ZonedDateTime.ofInstant(base, ZoneOffset.UTC)
67+
.plusYears(duration)
68+
.toInstant();
6069
};
6170
}
6271
}

0 commit comments

Comments
 (0)