<commit_before>/*******************************************************************************
 * Copyright SemanticBits, Northwestern University and Akaza Research
 * 
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/caaers/LICENSE.txt for details.
 ******************************************************************************/
package gov.nih.nci.cabig.caaers.utils;

import gov.nih.nci.cabig.caaers.domain.DateValue;

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

import org.apache.commons.lang.StringUtils;

/**
 * @author <NAME>
 * */
public class DateUtils {

    public static final String DATE_PATTERN= "MM/dd/yyyy";
    public static final String WS_DATE_PATTERN= "yyyy-MM-dd'T'HH:mm:ss";
    public static final String DATE_PATTERN_WITH_TZ= "EEE MMM dd yyyy h:mm:ss a z";
    public static final String DATE_WITH_HYPHENS= "MM-dd-yyyy";
    public static final String DATE_WITH_DATETIME= "MM/dd/yyyy HH:mm";
    
    /**
     * Will return the difference in minutes between the two dates
     * @param d1
     * @param d2
     * @return
     */
    public static long differenceInMinutes(Date d1, Date d2){
         if(d1 == null  || d2 == null) return Long.MAX_VALUE;
         long  l1 = d1.getTime();
         long l2 = d2.getTime();
         return ( l1 - l2) / (1000 * 60);
    }
	/**
	 * Checks whether the given d, is greater than or equal to startDate and less than or equal to endDate.
	 * @param d, cannot be null
	 * @param startDate, cannot be null
	 * @param endDate, if null ignored
	 * @return
	 * {@link NullPointerException} if d or startDate is null
	 */
	public static boolean between(Date d, Date startDate, Date endDate){
		if(endDate == null){
			return compareDate(d, startDate) >=0;
		}else if (compareDate(endDate, d) ==  0){
			return false;
		}else{
			return compareDate(d, startDate) >= 0 && compareDate(d , endDate) <=0;
		}
	}
	
	/**
	 * This is a convenient method to get yesterday date
	 * @return
	 */
	public static Date yesterday(){
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, -1);
		return c.getTime();
	}
	
	/**
	 * This is a convenient method to get tomorrow
	 * @return
	 */
	public static Date tomorrow(){
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, 1);
		return c.getTime();
	}
	
	public static Date today(){
		Calendar c = Calendar.getInstance();
		return c.getTime();
	}

    public static Date firstDayOfThisMonth(){
        return firstDayOfThisMonth(today());
    }

    /**
     * Will return the date representing the first day of this month
     * @param currDate
     * @return
     */
    public static Date firstDayOfThisMonth(Date currDate){<commit_msg>Fixed Testcases related to Dates.<commit_after>/*******************************************************************************
 * Copyright SemanticBits, Northwestern University and Akaza Research
 * 
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/caaers/LICENSE.txt for details.
 ******************************************************************************/
package gov.nih.nci.cabig.caaers.utils;

import gov.nih.nci.cabig.caaers.domain.DateValue;

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

import org.apache.commons.lang.StringUtils;

/**
 * @author <NAME>
 * */
public class DateUtils {

    public static final String DATE_PATTERN= "MM/dd/yyyy";
    public static final String WS_DATE_PATTERN= "yyyy-MM-dd'T'HH:mm:ss";
    public static final String DATE_PATTERN_WITH_TZ= "EEE MMM dd yyyy h:mm:ss a z";
    public static final String DATE_WITH_HYPHENS= "MM-dd-yyyy";
    public static final String DATE_WITH_DATETIME= "MM/dd/yyyy HH:mm";
    
    /**
     * Will return the difference in minutes between the two dates
     * @param d1
     * @param d2
     * @return
     */
    public static long differenceInMinutes(Date d1, Date d2){
         if(d1 == null  || d2 == null) return Long.MAX_VALUE;
         long  l1 = d1.getTime();
         long l2 = d2.getTime();
         return ( l1 - l2) / (1000 * 60);
    }
	/**
	 * Checks whether the given d, is greater than or equal to startDate and less than or equal to endDate.
	 * @param d, cannot be null
	 * @param startDate, cannot be null
	 * @param endDate, if null ignored
	 * @return
	 * {@link NullPointerException} if d or startDate is null
	 */
	public static boolean between(Date d, Date startDate, Date endDate){
		if(endDate == null){
			return compareDate(d, startDate) >=0;
		}else if (compareDate(endDate, d) ==  0){
			return false;
		}else{
			return compareDate(d, startDate) >= 0 && compareDate(d , endDate) <=0;
		}
	}
	
	/**
	 * This is a convenient method to get yesterday date
	 * @return
	 */
	public static Date yesterday(){
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, -1);
		Date d = c.getTime();
		d.setHours(0);
		d.setMinutes(0);
		return d;
	}
	
	/**
	 * This is a convenient method to get tomorrow
	 * @return
	 */
	public static Date tomorrow(){
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, 1);
		
		Date d = c.getTime();
		d.setHours(0);
		d.setMinutes(0);
		
		return d;
	}
	
	public static Date today(){
		Calendar c = Calendar.getInstance();
		
		Date d = c.getTime();
		d.setHours(0);
		d.setMinutes(0);
		
		return d;
	}

    public static Date firstDayOfThisMonth(){
        return firstDayOfThisMonth(today());
    }

    /**
     * Will return the date representing the first day of this month
     * @param currDate
     * @return
     */
    public static Date firstDayOfThisMonth(Date currDate){
{'fraction_non_alphanumeric': 0.1641300588031823, 'fraction_numerical': 0.009685230024213076, 'mean_word_length': 3.3481203007518796, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4370717', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1755, 'n_words': 550}