Consider an easier date adjuster #286

jodastephen opened this Issue Mar 20, 2013 · 7 comments

2 participants

ThreeTen member

TemporalAdjuster is based on the low level Temporal, whereas most adjustments want to be written for LocalDate. Consider the following which may help:

     * Obtains a {@code TemporalAdjuster} that wraps a date adjuster.
     * <p>
     * The {@code TemporalAdjuster} is based on the low level {@code Temporal} interface.
     * This method allows an adjustment from {@code LocalDate} to {@code LocalDate}
     * to be wrapped to match the temporal-based interface.
     * @return the temporal adjuster wrapping on the date adjuster, not null
    public static TemporalAdjuster ofDateAdjuster(UnaryOperator<LocalDate> adjuster) {
        return (temporal) -> {
            LocalDate input = LocalDate.from(temporal);
            LocalDate output = adjuster.apply(input);
            return temporal.with(output);

Note, its not certain that this necessarily helps, or whether it should be hidden internally as part of a streams API.


What exceptions can ofDateAdjuster throw?

ThreeTen member

None. The returned adjuster might throw exceptions.

Still not sure that this is worth it yet though.

ThreeTen member

I think this is worth doing, as pretty much all implementations I can foresee in my day job are date-based, and this method makes writing them significantly easier.


How would it be used? It might lead to adjusters that make incorrect assumptions that are ISO biased, like the days in months, etc.
I don't it as that valuable.

ThreeTen member

I've pointed out many times before that running algorithms or manipulations on dates in an arbitrary/unknown calendar system is risky and likely to go wrong, due to the wide variation in calendar systems. Most business applications (what Java is principally used for) use ISO for algorithms, so making it easier to write correct ISO adjusters is a good thing, not a bad one.

The method would be used to help users write adjusters.

public static TemporalAdjuster TWEAKER = TemporalAdjuster.ofDateAdjuster(date -> { ... });
@jodastephen jodastephen was assigned Apr 1, 2013
@jodastephen jodastephen closed this Apr 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment