Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Nov 3, 2022
1 parent a6f9231 commit 36b5c80
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ ZoneOffset after() {
}
}

/** Prefer {@link LocalDate#ofInstant(Instant, ZoneId)} over more indirect alternatives. */
static final class LocalDateOfInstant {
@BeforeTemplate
LocalDate before(Instant instant, ZoneId zoneId) {
return Refaster.anyOf(
instant.atZone(zoneId).toLocalDate(),
instant.atZone(zoneId).toOffsetDateTime().toLocalDate(),
OffsetDateTime.ofInstant(instant, zoneId).toLocalDate(),
LocalDateTime.ofInstant(instant, zoneId).toLocalDate());
}

Expand All @@ -86,12 +87,13 @@ LocalDate after(Instant instant, ZoneId zoneId) {
}
}

/** Prefer {@link LocalDateTime#ofInstant(Instant, ZoneId)} over more indirect alternatives. */
static final class LocalDateTimeOfInstant {
@BeforeTemplate
LocalDateTime before(Instant instant, ZoneId zoneId) {
return Refaster.anyOf(
instant.atZone(zoneId).toLocalDateTime(),
instant.atZone(zoneId).toOffsetDateTime().toLocalDateTime());
OffsetDateTime.ofInstant(instant, zoneId).toLocalDateTime());
}

@BeforeTemplate
Expand All @@ -105,12 +107,14 @@ LocalDateTime after(Instant instant, ZoneId zoneId) {
}
}

/** Prefer {@link LocalTime#ofInstant(Instant, ZoneId)} over more indirect alternatives. */
static final class LocalTimeOfInstant {
@BeforeTemplate
LocalTime before(Instant instant, ZoneId zoneId) {
return Refaster.anyOf(
instant.atZone(zoneId).toLocalTime(),
instant.atZone(zoneId).toOffsetDateTime().toLocalTime(),
OffsetDateTime.ofInstant(instant, zoneId).toLocalTime(),
OffsetTime.ofInstant(instant, zoneId).toLocalTime(),
LocalDateTime.ofInstant(instant, zoneId).toLocalTime());
}

Expand All @@ -125,7 +129,20 @@ LocalTime after(Instant instant, ZoneId zoneId) {
}
}

/** Prefer {@link Instant#atOffset(ZoneOffset)} over the more verbose alternative. */
/** Prefer {@link OffsetDateTime#ofInstant(Instant, ZoneId)} over more indirect alternatives. */
static final class OffsetDateTimeOfInstant {
@BeforeTemplate
OffsetDateTime before(Instant instant, ZoneId zoneId) {
return instant.atZone(zoneId).toOffsetDateTime();
}

@AfterTemplate
OffsetDateTime after(Instant instant, ZoneId zoneId) {
return OffsetDateTime.ofInstant(instant, zoneId);
}
}

/** Prefer {@link Instant#atOffset(ZoneOffset)} over more verbose alternatives. */
static final class InstantAtOffset {
@BeforeTemplate
OffsetDateTime before(Instant instant, ZoneOffset zoneOffset) {
Expand All @@ -138,10 +155,11 @@ OffsetDateTime after(Instant instant, ZoneOffset zoneOffset) {
}
}

/** Prefer {@link OffsetTime#ofInstant(Instant, ZoneId)} over more indirect alternatives. */
static final class OffsetTimeOfInstant {
@BeforeTemplate
OffsetTime before(Instant instant, ZoneId zoneId) {
return instant.atZone(zoneId).toOffsetDateTime().toOffsetTime();
return OffsetDateTime.ofInstant(instant, zoneId).toOffsetTime();
}

@BeforeTemplate
Expand All @@ -155,7 +173,7 @@ OffsetTime after(Instant instant, ZoneId zoneId) {
}
}

/** Prefer {@link Instant#atZone(ZoneId)} over the more verbose alternative. */
/** Prefer {@link Instant#atZone(ZoneId)} over more verbose alternatives. */
static final class InstantAtZone {
@BeforeTemplate
ZonedDateTime before(Instant instant, ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,29 @@ ImmutableSet<ZoneId> testUtcConstant() {
ImmutableSet<LocalDate> testLocalDateOfInstant() {
return ImmutableSet.of(
Instant.EPOCH.atZone(ZoneId.of("Europe/Amsterdam")).toLocalDate(),
Instant.EPOCH.atZone(ZoneId.of("Europe/Paris")).toOffsetDateTime().toLocalDate(),
Instant.EPOCH.atOffset(ZoneOffset.UTC).toLocalDate(),
LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")).toLocalDate());
OffsetDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")).toLocalDate(),
LocalDateTime.ofInstant(Instant.EPOCH, ZoneOffset.MIN).toLocalDate());
}

ImmutableSet<LocalDateTime> testLocalDateTimeOfInstant() {
return ImmutableSet.of(
Instant.EPOCH.atZone(ZoneId.of("Europe/Amsterdam")).toLocalDateTime(),
Instant.EPOCH.atZone(ZoneId.of("Europe/Berlin")).toOffsetDateTime().toLocalDateTime(),
Instant.EPOCH.atOffset(ZoneOffset.UTC).toLocalDateTime());
Instant.EPOCH.atOffset(ZoneOffset.UTC).toLocalDateTime(),
OffsetDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")).toLocalDateTime());
}

ImmutableSet<LocalTime> testLocalTimeOfInstant() {
return ImmutableSet.of(
Instant.EPOCH.atZone(ZoneId.of("Europe/Amsterdam")).toLocalTime(),
Instant.EPOCH.atZone(ZoneId.of("Europe/Paris")).toOffsetDateTime().toLocalTime(),
Instant.EPOCH.atOffset(ZoneOffset.UTC).toLocalTime(),
LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")).toLocalTime());
OffsetDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")).toLocalTime(),
OffsetTime.ofInstant(Instant.EPOCH, ZoneOffset.MIN).toLocalTime(),
LocalDateTime.ofInstant(Instant.EPOCH, ZoneOffset.MAX).toLocalTime());
}

OffsetDateTime testOffsetDateTimeOfInstant() {
return Instant.EPOCH.atZone(ZoneOffset.UTC).toOffsetDateTime();
}

OffsetDateTime testInstantAtOffset() {
Expand All @@ -65,7 +70,7 @@ OffsetDateTime testInstantAtOffset() {

ImmutableSet<OffsetTime> testOffsetTimeOfInstant() {
return ImmutableSet.of(
Instant.EPOCH.atZone(ZoneId.of("Europe/Amsterdam")).toOffsetDateTime().toOffsetTime(),
OffsetDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Amsterdam")).toOffsetTime(),
Instant.EPOCH.atOffset(ZoneOffset.UTC).toOffsetTime());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,29 @@ ImmutableSet<ZoneId> testUtcConstant() {
ImmutableSet<LocalDate> testLocalDateOfInstant() {
return ImmutableSet.of(
LocalDate.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Amsterdam")),
LocalDate.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Paris")),
LocalDate.ofInstant(Instant.EPOCH, ZoneOffset.UTC),
LocalDate.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")));
LocalDate.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")),
LocalDate.ofInstant(Instant.EPOCH, ZoneOffset.MIN));
}

ImmutableSet<LocalDateTime> testLocalDateTimeOfInstant() {
return ImmutableSet.of(
LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Amsterdam")),
LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")),
LocalDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC));
LocalDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC),
LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")));
}

ImmutableSet<LocalTime> testLocalTimeOfInstant() {
return ImmutableSet.of(
LocalTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Amsterdam")),
LocalTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Paris")),
LocalTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC),
LocalTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")));
LocalTime.ofInstant(Instant.EPOCH, ZoneId.of("Europe/Berlin")),
LocalTime.ofInstant(Instant.EPOCH, ZoneOffset.MIN),
LocalTime.ofInstant(Instant.EPOCH, ZoneOffset.MAX));
}

OffsetDateTime testOffsetDateTimeOfInstant() {
return OffsetDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC);
}

OffsetDateTime testInstantAtOffset() {
Expand Down

0 comments on commit 36b5c80

Please sign in to comment.