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

devonfw / IDEasy / 12765847701

14 Jan 2025 10:34AM UTC coverage: 68.082% (+0.5%) from 67.541%
12765847701

push

github

web-flow
#759: upgrade settings commandlet (#820)

2689 of 4311 branches covered (62.38%)

Branch coverage included in aggregate %.

6946 of 9841 relevant lines covered (70.58%)

3.1 hits per line

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

66.67
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_PATH = new DateTimeFormatterBuilder().appendPattern("YYYY/MM/dd")
5✔
15
      .toFormatter();
2✔
16

17
  private static final DateTimeFormatter DATE_FORMATTER_NAME = new DateTimeFormatterBuilder().appendPattern("YYYY-MM-dd")
5✔
18
      .toFormatter();
2✔
19

20
  private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder().appendPattern("HH-mm-ss")
6✔
21
      .toFormatter();
2✔
22

23
  // construction forbidden
24
  private DateTimeUtil() {
25

26
  }
27

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

35
    if ((start == null) || (end == null)) {
4!
36
      return false;
×
37
    }
38
    return start.isAfter(end);
4✔
39
  }
40

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

48
    if ((start == null) || (end == null)) {
4!
49
      return false;
×
50
    }
51
    return start.isBefore(end);
4✔
52
  }
53

54
  /**
55
   * @param start the start {@link Instant}.
56
   * @param end the end {@link Instant}.
57
   * @param duration the {@link Duration} to compare to.
58
   * @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
59
   *     is greater and {@code null} if one of the given values was {@code null}.
60
   */
61
  public static Integer compareDuration(Instant start, Instant end, Duration duration) {
62

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

70
  /**
71
   * @param temporal the {@link LocalDateTime} to format as date.
72
   * @param dirs {@code true} to use "/" as separator to create subfolders per year, month, and date, {@code false} otherwise.
73
   * @return the {@link LocalDateTime} formatted as date in the format YYYY-MM-dd or YYYY/MM/dd.
74
   */
75
  public static String formatDate(LocalDateTime temporal, boolean dirs) {
76

77
    if (dirs) {
2!
78
      return temporal.format(DATE_FORMATTER_PATH);
4✔
79
    } else {
80
      return temporal.format(DATE_FORMATTER_NAME);
×
81
    }
82
  }
83

84
  /**
85
   * @param temporal the {@link LocalDateTime} to format as time.
86
   * @return the {@link LocalDateTime} formatted as time in the format HH-mm-ss.
87
   */
88
  public static String formatTime(LocalDateTime temporal) {
89

90
    return temporal.format(TIME_FORMATTER);
4✔
91
  }
92

93
}
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