public static long goDurationToNanoseconds(String goDuration, String field) {
        requireNonNull(goDuration);

        Matcher matcher = SIMPLE_GO_DURATION_FORMAT.matcher(goDuration);
        if (!matcher.matches()) {
            String message = String.format("Unsupported duration value \"%s\" for the field \"%s\"", goDuration, field);
            throw new IllegalArgumentException(message);
        }
        long duration = Long.parseLong(matcher.group(1));
        if (matcher.groupCount() == 2 && matcher.group(2) != null) {
            String type = matcher.group(2);

            if (GO_TYPES_TO_JAVA.containsKey(type)) {
                duration = TimeUnit.NANOSECONDS.convert(duration, GO_TYPES_TO_JAVA.get(type));
            } else if ("w".equals(type)) {
                duration = 7 * TimeUnit.NANOSECONDS.convert(duration, TimeUnit.DAYS);
            } else if ("y".equals(type)) {
                duration = 365 * TimeUnit.NANOSECONDS.convert(duration, TimeUnit.DAYS);
            } else {
                throw new IllegalArgumentException("Unsupported time unit: " + type);
            }
        }

        return duration;
    }
Partial implementation of the patterns from https://pkg.go.dev/maze.io/x/duration
This implementation doesn't support combinations of timeunits.
src/main/java/io/fabric8/maven/docker/access/util/ComposeDurationUtil.java