@Override
    public Optional<ColumnMapper<?>> build(Type type, ConfigRegistry config) {
        if (type != Period.class) {
            return Optional.empty();
        }
        return Optional.of((r, i, c) -> {
            final Object obj = r.getObject(i);
            if (obj == null) {
                return null;
            }
            if (!(obj instanceof PGInterval)) {
                throw new IllegalArgumentException(String.format("got non-pginterval %s", obj));
            }
            final PGInterval interval = (PGInterval) obj;
            if (interval.getHours() != 0 || interval.getMinutes() != 0 || interval.getSeconds() != 0) {
                throw new IllegalArgumentException(
                        String.format("pginterval \"%s\" is too granular to be represented as period",
                                interval.getValue()));
            }
            return Period.of(interval.getYears(), interval.getMonths(), interval.getDays());
        });
    }
A column mapper which maps Postgres's {@link PGInterval} type to Java's {@link Period}.

<p>
Not all {@link PGInterval}s are representable as {@link Period}s. E.g., one with minutes. An
{@link IllegalArgumentException} will be thrown in this case.
postgres/src/main/java/org/jdbi/v3/postgres/PeriodColumnMapperFactory.java