<commit_before>package util;

import play.Logger;
import play.data.binding.Global;
import play.data.binding.TypeBinder;
import java.lang.annotation.Annotation;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

import models.Field;
import play.data.binding.AnnotationHelper;
import play.libs.I18N;
import play.mvc.Http.Request;

/**
 * Binder that support Date class.
 */
@Global
public class DateBinder implements TypeBinder<Date> {

    public static final String ISO8601 = "'ISO8601:'yyyy-MM-dd'T'HH:mm:ssZ";

    public Date bind(String name, Annotation[] annotations, String value, Class actualClass) throws Exception {

    	Field field = getAnnotation(Field.class, annotations);
    	String time = null;
    	if(field != null){
    		 time = Request.current().params.get(name+"."+field.value()+"_time");
    	}
    	Logger.debug("Invoked date binder for %s=%s time: %s", name, value, time);
    	
        Date date = AnnotationHelper.getDateAs(annotations, value);
        if (date != null) {
            return addTime(date, time);
        }

        try {
            SimpleDateFormat sdf = new SimpleDateFormat(I18N.getDateFormat());
            sdf.setLenient(false);
            return addTime(sdf.parse(value), time);
        } catch (ParseException e) {
             // Ignore
        }

        try {
            SimpleDateFormat sdf = new SimpleDateFormat(ISO8601);
            sdf.setLenient(false);
            return addTime(sdf.parse(value), time);
        } catch(Exception e) {
            throw new IllegalArgumentException("Cannot convert [" + value + "] to a Date: " + e.toString());
        }
        
    }

	private Date addTime(Date date, String time) {
		if(StringUtils.isEmpty(time))
			return date;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
            sdf.setLenient(false);
            Date timeDate = sdf.parse(time);
            
            date.setHours(timeDate.getHours());
            date.setMinutes(timeDate.getMinutes());
            return date;
        } catch(Exception e) {
            throw new IllegalArgumentException("Cannot convert [" + time + "] to a Time: " + e.toString());
        }

	}

	private <T extends Annotation> T getAnnotation(Class<T> klass, Annotation[] annotations) {
		for(Annotation ann : annotations)
			if(klass.isAssignableFrom(ann.getClass()))
				return (T) ann;
		return null;
	}

}<commit_msg>DateBinder: adapted for play 1.2<commit_after>package util;

import play.Logger;
import play.data.binding.Global;
import play.data.binding.TypeBinder;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

import models.Field;
import play.data.binding.AnnotationHelper;
import play.libs.I18N;
import play.mvc.Http.Request;

/**
 * Binder that support Date class.
 */
@Global
public class DateBinder implements TypeBinder<Date> {

    public static final String ISO8601 = "'ISO8601:'yyyy-MM-dd'T'HH:mm:ssZ";

    public Date bind(String name, Annotation[] annotations, String value, Class actualClass, Type genericType) throws Exception {

    	Field field = getAnnotation(Field.class, annotations);
    	String time = null;
    	if(field != null){
    		 time = Request.current().params.get(name+"."+field.value()+"_time");
    	}
    	Logger.debug("Invoked date binder for %s=%s time: %s", name, value, time);
    	
        Date date = AnnotationHelper.getDateAs(annotations, value);
        if (date != null) {
            return addTime(date, time);
        }

        try {
            SimpleDateFormat sdf = new SimpleDateFormat(I18N.getDateFormat());
            sdf.setLenient(false);
            return addTime(sdf.parse(value), time);
        } catch (ParseException e) {
             // Ignore
        }

        try {
            SimpleDateFormat sdf = new SimpleDateFormat(ISO8601);
            sdf.setLenient(false);
            return addTime(sdf.parse(value), time);
        } catch(Exception e) {
            throw new IllegalArgumentException("Cannot convert [" + value + "] to a Date: " + e.toString());
        }
        
    }

	private Date addTime(Date date, String time) {
		if(StringUtils.isEmpty(time))
			return date;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
            sdf.setLenient(false);
            Date timeDate = sdf.parse(time);
            
            date.setHours(timeDate.getHours());
            date.setMinutes(timeDate.getMinutes());
            return date;
        } catch(Exception e) {
            throw new IllegalArgumentException("Cannot convert [" + time + "] to a Time: " + e.toString());
        }

	}

	private <T extends Annotation> T getAnnotation(Class<T> klass, Annotation[] annotations) {
		for(Annotation ann : annotations)
			if(klass.isAssignableFrom(ann.getClass()))
				return (T) ann;
		return null;
	}
}
{'fraction_non_alphanumeric': 0.1184496737195966, 'fraction_numerical': 0.006723353767055566, 'mean_word_length': 2.7082111436950145, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1273400', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1473, 'n_words': 348}