private Function<String, Instant> createWeekBasedParser(final FieldSet fieldSet,
                                                         final DateTimeFormatterBuilder builder,
                                                         final ZoneId zoneId) {
        final ZonedDateTime referenceDateTime = getBaseTime().atZone(zoneId);

        if (!fieldSet.contains(WEEK_BASED_YEAR)
            && !fieldSet.contains(YEAR_OF_ERA)
            && !fieldSet.contains(YEAR)) {
            builder.parseDefaulting(WEEK_FIELDS.weekBasedYear(), referenceDateTime.get(WEEK_FIELDS.weekBasedYear()));
        }
        if (!fieldSet.contains(WEEK_OF_WEEK_BASED_YEAR)) {
            if (!fieldSet.contains(WEEK_OF_YEAR)
                && !fieldSet.contains(WEEK_OF_MONTH)) {
                builder.parseDefaulting(WEEK_FIELDS.weekOfWeekBasedYear(),
                        referenceDateTime.get(WEEK_FIELDS.weekOfWeekBasedYear()));
            } else if (fieldSet.contains(WEEK_OF_MONTH)) {
                builder.parseDefaulting(ChronoField.MONTH_OF_YEAR, referenceDateTime.get(ChronoField.MONTH_OF_YEAR));
                builder.parseDefaulting(ChronoField.YEAR_OF_ERA, referenceDateTime.get(ChronoField.YEAR_OF_ERA));
            } else {
                builder.parseDefaulting(ChronoField.YEAR_OF_ERA, referenceDateTime.get(ChronoField.YEAR_OF_ERA));
            }
        }
        if (!fieldSet.contains(DAY_OF_WEEK)) {
            builder.parseDefaulting(WEEK_FIELDS.dayOfWeek(), referenceDateTime.get(WEEK_FIELDS.dayOfWeek()));
        }

        final DateTimeFormatter formatter = builder.toFormatter(LOCALE);
        return new WeekBasedParser(fieldSet, formatter, zoneId, referenceDateTime);
    }
Parsing dates that use week fields has to be done differently as week based parsing does not seem to
cope with conflicting default values for fields.
stroom-pipeline/src/main/java/stroom/pipeline/xsltfunctions/ParseDateTime.java