Package com.google.errorprone.bugpatterns.time
package com.google.errorprone.bugpatterns.time
-
ClassesClassDescriptionWarns against suspect looking calls to
DateAPIs.Bans calls toDuration.get(temporalUnit)wheretemporalUnitis notSECONDSorNANOS.Bans calls toDurationAPIs where theTemporalUnitis notChronoUnit.DAYSor it has an estimated duration (which is guaranteed to throw anDateTimeException).Reports an error when a Duration or Instant is incorrectly decomposed in order to call an API which accepts a<long, TimeUnit>pair.Bans calls tojavaTimeType.from(temporalAmount)where the call is guaranteed to either: throw aDateTimeExceptionat runtime (e.g.,LocalDate.from(month)) return the same parameter (e.g.,Instant.from(instant))Bans calls toInstantAPIs where theTemporalUnitis not one of:NANOS,MICROS,MILLIS,SECONDS,MINUTES,HOURS,HALF_DAYS, orDAYS.This checker errors on calls tojava.timemethods using values that are guaranteed to throw aDateTimeException.This checker warns about calls toduration.getNano()without a corresponding "nearby" call toduration.getSeconds().Error prone checking forDuration.getSeconds()withoutDuration.getNano().Check for calls toduration.withNanos(int).Check for calls toduration.withSeconds(long).This checker warns about calls toinstant.getNano()without a corresponding "nearby" call toinstant.getEpochSecond().This checker warns about calls toLocalDateTime.getNano()without a corresponding "nearby" call toLocalDateTime.getSecond().This checker warns about calls toLocalTime.getNano()without a corresponding "nearby" call toLocalTime.getSecond().This checker warns about calls toperiod.getDays()without a corresponding "nearby" call toperiod.getYears(), period.getMonths(), or period.getTotalMonths().Check for calls tojava.timeAPIs that silently use the default system time-zone.Check for calls to bad JodaTime constructors.Checks for usages of dangerousDateTimeConstantsconstants.Check for calls toduration.withMillis(long).Check for calls toinstant.withMillis(long).Match possibly incorrect use of Period to obtain a number of (e.g.) days between two dates.Check for calls to JodaTime'stype.plus(long)andtype.minus(long)where<type> = {Duration,Instant,DateTime,DateMidnight}.Ban usage of Joda'sConverterManager.Check for calls to Joda-Time'sfoo.toFoo()andnew Foo(foo).Check for calls to JodaTime'stype.withDurationAdded(long, int)where<type> = {Duration,Instant,DateTime}.Bans calls toLocalDate.plus(TemporalAmount)andLocalDate.minus(TemporalAmount)where theTemporalAmountis a non-zeroDuration.Utility class to find calls "nearby" other calls.Bans calls toPeriod.get(temporalUnit)wheretemporalUnitis notYEARS,MONTHS, orDAYS.Bans calls toPeriod#plus/minus(TemporalAmount)where the argument is a Duration.This check suggests the use ofjava.time-based APIs, when available.This checker warns about accessing the underlying nanosecond-adjustment field of a duration without a "nearby" access of the underlying seconds field.This checker warns about accessing the underlying nanosecond-adjustment field of a protobuf timestamp without a "nearby" access of the underlying seconds field.Flags fields which would be better expressed as time types rather than primitive integers.Bans calls toTemporalAccessor.get(ChronoField)where the implementation is guaranteed to throw anUnsupportedTemporalTypeException.A BugPattern; see the summary.Check for problematic or suspicious TimeUnit conversion calls.Checker that detects likely time-unit mismatches by looking at identifier names.This checker bans calls toZoneId.of("Z")in favor ofZoneOffset.UTC.