dropwizard/dropwizard — pull request #443 by gtrog (2014-01-02 16:10:30+00:00)
Title: Add support for date-time offset values in configuration files

I'd like to add the ability to specify something I'd like to call date time offset, which relates directly to JodaTime's plusDays(), plusWeeks(), etc. functions. I had a need to be able to specify an offset value in the format '+1 day', and '-1 day', etc. At first I attempted to use Duration. Duration doesn't support negative values or explicit positive values, and after giving it some more thought, I decided that this type of thing is an entirely different concept than Duration anyways and the units Duration supports isn't directly in line with what JodaTime allows you to plus/minus from DateTime instances. I've left out the ability to convert between units for now as this can get fairly complex for cases like converting days to months, etc. I wanted to keep the functionality simply for representing an offset and applying it, not much more.

Examples:

MyConfiguration.java:

public class MyConfiguration extends Configuration {
private DateTimeOffset start;
// public getStart()/setStart()...
private DateTimeOffset end;
// public getEnd()/setEnd()...
}

config.yaml:
start: -1 day
end: +5 days

Usage:
MyConfiguration configuration = ...;
configuration.getStart().apply(DateTime.now()); // calls plusDays(-1) on instance