<commit_before>package wint.lang.convert.converts;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

import wint.lang.exceptions.DateParseException;
import wint.lang.utils.CollectionUtil;

public class SmartDateConvert extends AbstractConvert<Date> {

	private static List<DatePatternConverter> datePatternConverts = CollectionUtil.newArrayList(); 
	
	public SmartDateConvert() {
	}
	
	static {
		datePatternConverts.add(new DatePatternConverter("\\d{4}\\-\\d{1,2}\\-\\d{1,2} \\d{2}:\\d{2}:\\d{2}", "yyyy-MM-dd HH:mm:ss"));
		datePatternConverts.add(new DatePatternConverter("\\d{4}\\-\\d{1,2}\\-\\d{1,2}", "yyyy-MM-dd"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\d{1,2}\\d{1,2}\\d{2}\\d{2}\\d{2}", "yyyyMMddHHmmss"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\d{1,2}\\d{1,2}", "yyyyMMdd"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\-\\d{1,2}\\-\\d{1,2} \\d{2}:\\d{2}", "yyyy-MM-dd HH:mm"));
        datePatternConverts.add(new DatePatternConverter("\\d{1,2}\\-\\d{1,2} \\d{2}:\\d{2}", "MM-dd HH:mm"));
        datePatternConverts.add(new DatePatternConverter("\\d{1,2}:\\d{1,2}:\\d{1,2}", "HH:mm:ss"));
        datePatternConverts.add(new DatePatternConverter("\\d{1,2}:\\d{1,2}", "HH:mm"));
        datePatternConverts.add(new DatePatternConverter("\\d{2}\\-\\d{1,2}\\-\\d{1,2}", "yy-MM-dd"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\/\\d{1,2}\\/\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}", "yyyy/MM/dd HH:mm:ss"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\/\\d{1,2}\\/\\d{1,2}", "yyyy/MM/dd"));
        datePatternConverts.add(new DatePatternConverter("\\d{2}\\/\\d{1,2}\\/\\d{1,2}", "yy/MM/dd"));
    }
	
	public Date convertTo(Object input, Date defaultValue) {
		if (input instanceof Date) {
			return (Date)input;
		}
		if (input == null) {
			return defaultValue;
		}
		String stringDate = input.toString();
		for (DatePatternConverter datePatternConverter : datePatternConverts) {
			if (datePatternConverter.matches(stringDate)) {
				return datePatternConverter.convert(stringDate);
			}
		}
		return defaultValue;
	}

	public Date getDefaultValue() {
		return null;
	}
	
	static class DatePatternConverter {
		
		private Pattern datePattern;
		
		private String dateFormat;
		
		public DatePatternConverter(String datePattern, String dateFormat) {<commit_msg>fixed<commit_after>package wint.lang.convert.converts;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

import wint.lang.exceptions.DateParseException;
import wint.lang.utils.CollectionUtil;

public class SmartDateConvert extends AbstractConvert<Date> {

	private static List<DatePatternConverter> datePatternConverts = CollectionUtil.newArrayList(); 
	
	public SmartDateConvert() {
	}
	
	static {
		datePatternConverts.add(new DatePatternConverter("\\d{4}\\-\\d{1,2}\\-\\d{1,2} \\d{2}:\\d{2}:\\d{2}", "yyyy-MM-dd HH:mm:ss"));
		datePatternConverts.add(new DatePatternConverter("\\d{4}\\-\\d{1,2}\\-\\d{1,2}", "yyyy-MM-dd"));
		datePatternConverts.add(new DatePatternConverter("\\d{4}\\-\\d{1,2}", "yyyy-MM"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\d{1,2}\\d{1,2}\\d{2}\\d{2}\\d{2}", "yyyyMMddHHmmss"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\d{1,2}\\d{1,2}", "yyyyMMdd"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\-\\d{1,2}\\-\\d{1,2} \\d{2}:\\d{2}", "yyyy-MM-dd HH:mm"));
        datePatternConverts.add(new DatePatternConverter("\\d{1,2}\\-\\d{1,2} \\d{2}:\\d{2}", "MM-dd HH:mm"));
        datePatternConverts.add(new DatePatternConverter("\\d{1,2}:\\d{1,2}:\\d{1,2}", "HH:mm:ss"));
        datePatternConverts.add(new DatePatternConverter("\\d{1,2}:\\d{1,2}", "HH:mm"));
        datePatternConverts.add(new DatePatternConverter("\\d{2}\\-\\d{1,2}\\-\\d{1,2}", "yy-MM-dd"));
        datePatternConverts.add(new DatePatternConverter("\\d{2}\\-\\d{1,2}", "yy-MM"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\/\\d{1,2}\\/\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}", "yyyy/MM/dd HH:mm:ss"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\/\\d{1,2}\\/\\d{1,2}", "yyyy/MM/dd"));
        datePatternConverts.add(new DatePatternConverter("\\d{4}\\/\\d{1,2}", "yyyy/MM"));
        datePatternConverts.add(new DatePatternConverter("\\d{2}\\/\\d{1,2}\\/\\d{1,2}", "yy/MM/dd"));
        datePatternConverts.add(new DatePatternConverter("\\d{2}\\/\\d{1,2}", "yy/MM"));
    }
	
	public Date convertTo(Object input, Date defaultValue) {
		if (input instanceof Date) {
			return (Date)input;
		}
		if (input == null) {
			return defaultValue;
		}
		String stringDate = input.toString();
		for (DatePatternConverter datePatternConverter : datePatternConverts) {
			if (datePatternConverter.matches(stringDate)) {
				return datePatternConverter.convert(stringDate);
			}
		}
		return defaultValue;
	}

	public Date getDefaultValue() {
		return null;
	}
	
	static class DatePatternConverter {
		
		private Pattern datePattern;
		
		private String dateFormat;
		
		public DatePatternConverter(String datePattern, String dateFormat) {
{'fraction_non_alphanumeric': 0.21457791000371884, 'fraction_numerical': 0.030122722201561918, 'mean_word_length': 4.022408963585434, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5834511', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1914, 'n_words': 260}