|
23 | 23 | import java.nio.file.Path; |
24 | 24 | import java.nio.file.Paths; |
25 | 25 | import java.text.SimpleDateFormat; |
| 26 | +import java.time.LocalDate; |
| 27 | +import java.time.ZoneId; |
26 | 28 | import java.util.ArrayList; |
27 | 29 | import java.util.Arrays; |
28 | 30 | import java.util.Calendar; |
29 | 31 | import java.util.Collection; |
30 | 32 | import java.util.Collections; |
| 33 | +import java.util.Date; |
31 | 34 | import java.util.HashSet; |
32 | 35 | import java.util.LinkedHashMap; |
33 | 36 | import java.util.List; |
@@ -472,22 +475,38 @@ public static boolean sonarLintVersionHintHidden() { |
472 | 475 | : Boolean.parseBoolean(property); |
473 | 476 | } |
474 | 477 |
|
475 | | - public static boolean isSonarLintVersionHintDateToday() { |
| 478 | + /** |
| 479 | + * Check whether it was already two weeks ago that the user got a hint about the new SonarQube |
| 480 | + * for Eclipse version. If it has not yet been two weeks, we don't want to show it again. |
| 481 | + */ |
| 482 | + public static boolean isNextSonarLintVersionHintDateToday() { |
476 | 483 | var date = getPreferenceString(PREF_SONARLINT_VERSION_HINT_DATE); |
477 | 484 | if (date.isBlank()) { |
478 | | - return false; |
| 485 | + return true; |
479 | 486 | } |
480 | 487 |
|
481 | 488 | try { |
482 | | - var today = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime()); |
483 | | - return date.equals(today); |
| 489 | + var savedDate = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).parse(date); |
| 490 | + var todayDate = Calendar.getInstance().getTime(); |
| 491 | + |
| 492 | + return todayDate.after(savedDate); |
484 | 493 | } catch (Exception ignored) { |
485 | 494 | return false; |
486 | 495 | } |
487 | 496 | } |
488 | 497 |
|
489 | | - public static void setSonarLintVersionHintDate() { |
490 | | - var date = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime()); |
| 498 | + /** |
| 499 | + * Only show hint about the new SonarQube for Eclipse version every two weeks in order to not |
| 500 | + * annoy users with a daily notification. |
| 501 | + */ |
| 502 | + public static void setNextSonarLintVersionHintDate() { |
| 503 | + var date = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH) |
| 504 | + .format(Date.from( |
| 505 | + LocalDate.now().plusDays(14) |
| 506 | + .atStartOfDay() |
| 507 | + .atZone(ZoneId.systemDefault()) |
| 508 | + .toInstant())); |
| 509 | + |
491 | 510 | setPreferenceString(getApplicationLevelPreferenceNode(), PREF_SONARLINT_VERSION_HINT_DATE, date); |
492 | 511 | } |
493 | 512 | } |
0 commit comments