<commit_before>package uk.nhs.ciao.docs.parser;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

/**
 * Property converter which converts a given date format into the canonical
 * date format used by HL7
 */
public class DatePropertyConverter implements PropertyConverter {
	private static final Logger LOGGER = LoggerFactory.getLogger(DatePropertyConverter.class);
	
	/**
	 * Standard Date format used by HL7
	 */
	private static final DateFormatThreadLocal HL7_FORMAT = new DateFormatThreadLocal("yyyyMMdd");
	
	private final DateFormatThreadLocal parseFormat;
	
	/**
	 * Constructs a new date property converter using the specified pattern as the input format
	 */
	public DatePropertyConverter(final String pattern) {
		parseFormat = new DateFormatThreadLocal(pattern);
	}
	
	@Override
	public String convertProperty(final String name, final String value) {
		if (Strings.isNullOrEmpty(value)) {
			return value;
		}
		
		try {
			final Date date = parseFormat.get().parse(value);
			return HL7_FORMAT.get().format(date);
		} catch (Exception e) {
			LOGGER.debug("Unable to parse property name: {} value: {} - continuing with original value",
					name, value, e);
			return value;
		}
	}
	
	/**
	 * ThreadLocal to contain simple date format instances (SimpleDateFormat is NOT thread-safe so
	 * synchronisation or thread-confinement is required)
	 */
	private static class DateFormatThreadLocal extends ThreadLocal<DateFormat> {
		private final String pattern;
		
		public DateFormatThreadLocal(final String pattern) {
			this.pattern = Preconditions.checkNotNull(pattern);
		}
		
		@Override
		protected DateFormat initialValue() {
			return new SimpleDateFormat(pattern);
		}
	}
}<commit_msg>Updated date format to use JODA time instead of SimpleDateFormat (JODA time is thread-safe by default)<commit_after>package uk.nhs.ciao.docs.parser;

import java.util.Locale;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;

/**
 * Property converter which converts a given date format into the canonical
 * date format used by HL7
 */
public class DatePropertyConverter implements PropertyConverter {
	private static final Logger LOGGER = LoggerFactory.getLogger(DatePropertyConverter.class);
	
	/**
	 * Standard Date format used by HL7
	 */
	private static final DateTimeFormatter HL7_FORMAT = DateTimeFormat.forPattern("yyyyMMdd").withLocale(Locale.getDefault());
	
	private final DateTimeFormatter parseFormat;
	
	/**
	 * Constructs a new date property converter using the specified pattern as the input format
	 */
	public DatePropertyConverter(final String pattern) {
		parseFormat = DateTimeFormat.forPattern(pattern);
	}
	
	@Override
	public String convertProperty(final String name, final String value) {
		if (Strings.isNullOrEmpty(value)) {
			return value;
		}
		
		try {
			final DateTime date = parseFormat.parseDateTime(value);
			return HL7_FORMAT.print(date);
		} catch (Exception e) {
			LOGGER.debug("Unable to parse property name: {} value: {} - continuing with original value",
					name, value, e);
			return value;
		}
	}
}
{'fraction_non_alphanumeric': 0.08705882352941176, 'fraction_numerical': 0.0035294117647058825, 'mean_word_length': 4.521103896103896, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '537986', 'n_tokens_mistral': 1027, 'n_tokens_neox': 921, 'n_words': 291}