Skip to content

Instantly share code, notes, and snippets.

@cwensel
Created November 9, 2023 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwensel/cdadcfba84fb039e9504709d4c5de733 to your computer and use it in GitHub Desktop.
Save cwensel/cdadcfba84fb039e9504709d4c5de733 to your computer and use it in GitHub Desktop.
Uses mini-parsers-temporal library to add duration strings to config files
import heretical.parser.temporal.DurationParser;
import org.eclipse.microprofile.config.spi.Converter;
import java.time.Duration;
/**
* Uses <a href="https://github.com/Heretical/mini-parsers">Mini-Parsers</a> to parse a duration string
* in a config file.
*/
public class DurationConverter implements Converter<Duration> {
DurationParser parser = new DurationParser();
@Override
public Duration convert(String value) throws IllegalArgumentException, NullPointerException {
return parser.parse(value).getResult();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment