• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 9907372175

12 Jul 2024 11:49AM UTC coverage: 61.142% (-0.02%) from 61.162%
9907372175

push

github

hohwille
fixed tests

1997 of 3595 branches covered (55.55%)

Branch coverage included in aggregate %.

5296 of 8333 relevant lines covered (63.55%)

2.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
cli/src/main/java/com/devonfw/tools/ide/util/DateTimeUtil.java
1
package com.devonfw.tools.ide.util;
2

3
import java.time.Duration;
4
import java.time.Instant;
5
import java.time.LocalDateTime;
6
import java.time.format.DateTimeFormatter;
7
import java.time.format.DateTimeFormatterBuilder;
8

9
/**
10
 * Utility class for operations on data and time (java.time).
11
 */
12
public final class DateTimeUtil {
13

14
  private static final DateTimeFormatter DATE_FORMATTER = new DateTimeFormatterBuilder().appendPattern("YYYY-MM-dd")
5✔
15
      .toFormatter();
2✔
16

17
  private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder().appendPattern("HH-mm-ss")
6✔
18
      .toFormatter();
2✔
19

20
  // construction forbidden
21
  private DateTimeUtil() {
22

23
  }
24

25
  /**
26
   * @param start the first {@link Instant}.
27
   * @param end the second {@link Instant}.
28
   * @return {@code true} if the first {@link Instant} is after the second.
29
   */
30
  public static boolean isAfter(Instant start, Instant end) {
31

32
    Integer delta = compareDuration(start, end, Duration.ZERO);
5✔
33
    if (delta == null) {
2!
34
      return false;
×
35
    }
36
    return delta.intValue() < 0;
7✔
37
  }
38

39
  /**
40
   * @param start the first {@link Instant}.
41
   * @param end the second {@link Instant}.
42
   * @return {@code true} if the first {@link Instant} is before the second.
43
   */
44
  public static boolean isBefore(Instant start, Instant end) {
45

46
    Integer delta = compareDuration(start, end, Duration.ZERO);
5✔
47
    if (delta == null) {
2!
48
      return false;
×
49
    }
50
    return delta.intValue() > 0;
7✔
51
  }
52

53
  /**
54
   * @param start the start {@link Instant}.
55
   * @param end the end {@link Instant}.
56
   * @param duration the {@link Duration} to compare to.
57
   * @return {@code 0} if the {@link Duration} from {@code start} to {@code end} is equal to the given {@link Duration}, negative value if less, positive value
58
   * is greater and {@code null} if one of the given values was {@code null}.
59
   */
60
  public static Integer compareDuration(Instant start, Instant end, Duration duration) {
61

62
    if ((start == null) || (end == null) || (duration == null)) {
6!
63
      return null;
×
64
    }
65
    Duration delta = Duration.between(start, end);
4✔
66
    return Integer.valueOf(delta.compareTo(duration));
5✔
67
  }
68

69
  /**
70
   * @param temporal the {@link LocalDateTime} to format as date.
71
   * @return the {@link LocalDateTime} formatted as date in the format YYYY-MM-dd.
72
   */
73
  public static String formatDate(LocalDateTime temporal) {
74

75
    return temporal.format(DATE_FORMATTER);
4✔
76
  }
77

78
  /**
79
   * @param temporal the {@link LocalDateTime} to format as time.
80
   * @return the {@link LocalDateTime} formatted as time in the format HH-mm-ss.
81
   */
82
  public static String formatTime(LocalDateTime temporal) {
83

84
    return temporal.format(TIME_FORMATTER);
4✔
85
  }
86

87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc