DateUtils.java

1
package org.cardanofoundation.explorer.api.util;
2
3
import java.time.Duration;
4
import java.time.Instant;
5
import java.time.LocalDate;
6
import java.time.LocalDateTime;
7
import java.time.ZoneOffset;
8
import java.time.temporal.TemporalAmount;
9
import java.util.ArrayList;
10
import java.util.List;
11
12
import lombok.experimental.UtilityClass;
13
14
import org.cardanofoundation.explorer.api.common.enumeration.AnalyticType;
15
16
@UtilityClass
17
public class DateUtils {
18
19
  private final TemporalAmount ONE_DAY_TIME_SEGMENT = Duration.ofHours(2);
20
  private final TemporalAmount ONE_WEEK_TIME_SEGMENT = Duration.ofDays(1);
21
  private final TemporalAmount ONE_MONTH_TIME_SEGMENT = Duration.ofDays(1);
22
  private final TemporalAmount THREE_MONTH_TIME_SEGMENT = Duration.ofDays(1);
23
24
  private final TemporalAmount ONE_DAY = Duration.ofDays(1);
25
  private final TemporalAmount ONE_WEEK = Duration.ofDays(7);
26
  private final TemporalAmount ONE_MONTH = Duration.ofDays(30);
27
  private final TemporalAmount THREE_MONTH = Duration.ofDays(90);
28
29
  public static List<LocalDateTime> getListDateAnalytic(AnalyticType analyticType) {
30
    LocalDate currentDate = LocalDate.ofInstant(Instant.now(), ZoneOffset.UTC);
31
    LocalDateTime startOfToday = currentDate.atStartOfDay();
32 1 1. getListDateAnalytic : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/util/DateUtils::getListDateAnalytic → KILLED
    return switch (analyticType) {
33
      case ONE_WEEK -> getDateAnalytics(
34
          startOfToday.minus(ONE_WEEK), currentDate.atStartOfDay(), ONE_WEEK_TIME_SEGMENT);
35
      case ONE_MONTH -> getDateAnalytics(
36
          startOfToday.minus(ONE_MONTH), currentDate.atStartOfDay(), ONE_MONTH_TIME_SEGMENT);
37
      case THREE_MONTH -> getDateAnalytics(
38
          startOfToday.minus(THREE_MONTH), currentDate.atStartOfDay(), THREE_MONTH_TIME_SEGMENT);
39
      default -> getDateAnalytics(
40
          startOfToday.minus(ONE_DAY), currentDate.atStartOfDay(), ONE_DAY_TIME_SEGMENT);
41
    };
42
  }
43
44
  private List<LocalDateTime> getDateAnalytics(
45
      LocalDateTime start, LocalDateTime end, TemporalAmount amountToSubtract) {
46
    List<LocalDateTime> dateAnalytics = new ArrayList<>();
47 1 1. getDateAnalytics : negated conditional → KILLED
    while (!start.isAfter(end)) {
48
      dateAnalytics.add(start);
49
      start = start.plus(amountToSubtract);
50
    }
51 1 1. getDateAnalytics : replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/util/DateUtils::getDateAnalytics → KILLED
    return dateAnalytics;
52
  }
53
}

Mutations

32

1.1
Location : getListDateAnalytic
Killed by : org.cardanofoundation.explorer.api.service.TokenServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.TokenServiceTest]/[method:testGetTokenVolumeAnalytic_WhenTokenFound_WithNotOneDayRangeAndExistsZeroBalance()]
replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/util/DateUtils::getListDateAnalytic → KILLED

47

1.1
Location : getDateAnalytics
Killed by : org.cardanofoundation.explorer.api.service.TokenServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.TokenServiceTest]/[method:testGetTokenVolumeAnalytic_WhenTokenFound_WithNotOneDayRangeAndExistsZeroBalance()]
negated conditional → KILLED

51

1.1
Location : getDateAnalytics
Killed by : org.cardanofoundation.explorer.api.service.TokenServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.TokenServiceTest]/[method:testGetTokenVolumeAnalytic_WhenTokenFound_WithNotOneDayRangeAndExistsZeroBalance()]
replaced return value with Collections.emptyList for org/cardanofoundation/explorer/api/util/DateUtils::getDateAnalytics → KILLED

Active mutators

Tests examined


Report generated by PIT 1.14.2