<commit_before>/*
 * UniTime 3.1 (University Timetabling Application)
 * Copyright (C) 2008, UniTime LLC, and individual contributors
 * as indicated by the @authors tag.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.unitime.timetable.util;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * @author <NAME>
 */
public class DateUtils {
    public static int getWeek(Date date) {
    	Calendar c = Calendar.getInstance(Locale.US);
    	c.setTime(date);
    	return c.get(Calendar.WEEK_OF_YEAR);
    }
    public static int getDayOfYear(Date date) {
    	Calendar c = Calendar.getInstance(Locale.US);
    	c.setTime(date);
    	return c.get(Calendar.DAY_OF_YEAR);
    }
    public static int getFirstDayOfWeek(int year, int week) {
		Calendar c = Calendar.getInstance(Locale.US);
		c.set(year,1,1,0,0,0);
		c.set(Calendar.WEEK_OF_YEAR,week);
		c.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
		int dayOfYear = c.get(Calendar.DAY_OF_YEAR); 
		if (c.get(Calendar.YEAR)<year) {
		    Calendar x = Calendar.getInstance(Locale.US);
		    x.set(c.get(Calendar.YEAR),11,31,0,0,0);
		    dayOfYear -= x.get(Calendar.DAY_OF_YEAR);
		}
		return dayOfYear;
    }
    public static Date getDate(int year, int dayOfYear) {
		Calendar c = Calendar.getInstance(Locale.US);
		c.set(year,1,1,0,0,0);
		c.set(Calendar.DAY_OF_YEAR,dayOfYear);
		return c.getTime();
    }
    public static Date getDate(int day, int month, int year) {
    	return calendarFor(day, month, year).getTime();
    }
    public static Date getStartDate(int year, int week) {
		Calendar c = Calendar.getInstance(Locale.US);
		c.set(year,1,1,0,0,0);
		c.set(Calendar.WEEK_OF_YEAR,week);
		c.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
		return c.getTime();
    }
    public static Date getEndDate(int year, int week) {
		Calendar c = Calendar.getInstance(Locale.US);
		c.set(year,1,1,0,0,0);
		c.set(Calendar.WEEK_OF_YEAR,week);
		c.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);
		return c.getTime();
    }<commit_msg>getFirstDayOfWeek -- fixed the case when week goes over a year end (week >= 53)<commit_after>/*
 * UniTime 3.1 (University Timetabling Application)
 * Copyright (C) 2008, UniTime LLC, and individual contributors
 * as indicated by the @authors tag.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.unitime.timetable.util;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * @author <NAME>
 */
public class DateUtils {
    public static int getWeek(Date date) {
    	Calendar c = Calendar.getInstance(Locale.US);
    	c.setTime(date);
    	return c.get(Calendar.WEEK_OF_YEAR);
    }
    public static int getDayOfYear(Date date) {
    	Calendar c = Calendar.getInstance(Locale.US);
    	c.setTime(date);
    	return c.get(Calendar.DAY_OF_YEAR);
    }
    public static int getFirstDayOfWeek(int year, int week) {
		Calendar c = Calendar.getInstance(Locale.US);
		c.set(year,1,1,0,0,0);
		c.set(Calendar.WEEK_OF_YEAR,week);
		c.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
		int dayOfYear = c.get(Calendar.DAY_OF_YEAR); 
		if (c.get(Calendar.YEAR)<year) {
		    Calendar x = Calendar.getInstance(Locale.US);
		    x.set(c.get(Calendar.YEAR),11,31,0,0,0);
		    dayOfYear -= x.get(Calendar.DAY_OF_YEAR);
		} else if (c.get(Calendar.YEAR)>year) {
			Calendar x = Calendar.getInstance(Locale.US);
		    x.set(year,11,31,0,0,0);
		    dayOfYear += x.get(Calendar.DAY_OF_YEAR);
		}
		return dayOfYear;
    }
    public static Date getDate(int year, int dayOfYear) {
		Calendar c = Calendar.getInstance(Locale.US);
		c.set(year,1,1,0,0,0);
		c.set(Calendar.DAY_OF_YEAR,dayOfYear);
		return c.getTime();
    }
    public static Date getDate(int day, int month, int year) {
    	return calendarFor(day, month, year).getTime();
    }
    public static Date getStartDate(int year, int week) {
		Calendar c = Calendar.getInstance(Locale.US);
		c.set(year,1,1,0,0,0);
		c.set(Calendar.WEEK_OF_YEAR,week);
		c.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
		return c.getTime();
    }
    public static Date getEndDate(int year, int week) {
		Calendar c = Calendar.getInstance(Locale.US);
		c.set(year,1,1,0,0,0);
		c.set(Calendar.WEEK_OF_YEAR,week);
		c.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);
		return c.getTime();
    }
{'fraction_non_alphanumeric': 0.11623353506585973, 'fraction_numerical': 0.01762192951228195, 'mean_word_length': 3.8439655172413794, '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': '4327508', 'n_tokens_mistral': 2017, 'n_tokens_neox': 1862, 'n_words': 523}