<commit_before>package edu.virginia.iath.snac.helpers;

import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

public class DateParserHelper {
	
	private String dateString = null;
	private String date1Str = null;
	private String date2Str = null;
	private Date date1 = null;
	private Date date2 = null;
	private String date1StrModifier = null;
	private String date2StrModifier = null;
	private static String outputFormat = "yyyy-MM-dd";
	

	public DateParserHelper(String dateStr) {
		// Store the date string locally
		dateString = dateStr.trim();
		
		// Parse the dates into Date objects
		runParser();
	}
	
	private void runParser() {
		// Check for date range.  If so, parse separately
		if (dateString.contains("-")) {
			date1Str = dateString.substring(0, dateString.indexOf("-")).trim();
			date2Str = dateString.substring(dateString.indexOf("-") + 1).trim();

			date1 = parseDate(date1Str);
			date2 = parseDate(date2Str);
		} else {
			date1Str = dateString.trim();
			date1 = parseDate(dateString);
		}
	}

	public boolean isRange() {
		return date2 != null;
	}

	public String firstDate() {
		return getOutputString(date1);
	}

	public String secondDate() {
		return getOutputString(date2);
	}

	public String getDate() {
		return getOutputString(date1);
	}
	
	private Date parseDate(String d) {
		try {
			// Currently we are ignoring "-" in the text, since that is used for ranges in dates
			return DateUtils.parseDate(d.trim(),
					"yyyy", /*"yyyy-MM", "yyyy-M", "yyyy-M-d", "yyyy-M-dd", "yyyy-MM-d", "yyyy-MM-dd",*/ // standard dates
					"MMMMM dd, yyyy", "MMM dd, yyyy", "MMM dd yyyy", "MMMMM dd, yyyy", "yyyy MMM dd",
					"dd MMM, yyyy", "dd MMMMM, yyyy", "yyyy, MMM dd", "yyyy, MMMMM dd", "yyyy, MMM. dd",
					"MMMMM yyyy", "MMM yyyy"
					);
		} catch (ParseException e) {
			return null;
		}
	}
	
	private String getOutputString(Date d) {
		return (d == null) ? "unparsable" : DateFormatUtils.format(d, outputFormat);
	}

}<commit_msg>Added handling for circa<commit_after>package edu.virginia.iath.snac.helpers;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

public class DateParserHelper {
	
	private String dateString = null;
	private String[] dateStr = null;
	private Date[] dates = null;
	private String[] dateStrModifier = null;
	private static String outputFormat = "yyyy-MM-dd";
	

	public DateParserHelper(String d) {
		dates = new Date[2];
		dateStr = new String[2];
		dateStrModifier = new String[2];
		
		// Store the date string locally
		dateString = d.trim();
		
		// Parse the dates into Date objects
		runParser();
	}
	
	private void runParser() {
		// Check for date range.  If so, parse separately
		if (dateString.contains("-")) {
			dateStr[0] = dateString.substring(0, dateString.indexOf("-")).trim();
			dateStr[1] = dateString.substring(dateString.indexOf("-") + 1).trim();
			
			// parse the two dates
			parseDate(0);
			parseDate(1);
		} else {
			dateStr[0] = dateString.trim();
			dates[1] = null;
			dateStr[1] = null;
			
			// parse the date
			parseDate(0);
		}
	}

	public boolean isRange() {
		return dates[1] != null;
	}

	public String firstDate() {
		return getOutputString(dates[0]) + " " + handleModifier(0);
	}

	public String secondDate() {
		return getOutputString(dates[1]) + " " + handleModifier(0);
	}

	public String getDate() {
		return getOutputString(dates[0]) + " " + handleModifier(0);
	}
	
	private void parseDate(int i) {
		dateStrModifier[i] = null;
		
		if (dateStr[i].contains("circa")) {
			dateStrModifier[i] = "circa";
			dateStr[i] = dateStr[i].replace("circa", "");
		}
		
		try {
			// Currently we are ignoring "-" in the text, since that is used for ranges in dates
			dates[i] = DateUtils.parseDate(dateStr[i].trim(),
					"yyyy", /*"yyyy-MM", "yyyy-M", "yyyy-M-d", "yyyy-M-dd", "yyyy-MM-d", "yyyy-MM-dd",*/ // standard dates
					"MMMMM dd, yyyy", "MMM dd, yyyy", "MMM dd yyyy", "MMMMM dd, yyyy", "yyyy MMM dd",
					"dd MMM, yyyy", "dd MMMMM, yyyy", "yyyy, MMM dd", "yyyy, MMMMM dd", "yyyy, MMM. dd",
					"MMMMM yyyy", "MMM yyyy"
					);
		} catch (ParseException e) {
			dates[i] = null;
		}
	}
	
	private String handleModifier(int i) {
		String output = "";
		if (dateStrModifier[i] != null) {
			if (dateStrModifier[i].equals("circa")) {
				Calendar d = Calendar.getInstance();
				d.setTime(dates[i]);
				d.add(Calendar.YEAR, -3);
				output += "( " + DateFormatUtils.format(d.getTime(), outputFormat) + " -- ";
				d.setTime(dates[i]);
				d.add(Calendar.YEAR, 3);
				output += DateFormatUtils.format(d.getTime(), outputFormat) + ")";
				
			}
		}
		return output;
	}
	
	private String getOutputString(Date d) {
		return (d == null) ? "unparsable" : DateFormatUtils.format(d, outputFormat);
	}

}
{'fraction_non_alphanumeric': 0.15241560541742472, 'fraction_numerical': 0.009298564786739438, 'mean_word_length': 3.5772432932469935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5998891', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1732, 'n_words': 433}