package scheduleGenerator;

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

/**
 * TODO Put here a description of what this class does.
 *
 * @author saslavns.
 *         Created Oct 23, 2012.
 */
public class DateTimePair {
	private Date date;
	private Time start, end;
	/**
	 * TODO Put here a description of what this constructor does.
	 *
	 * @param date
	 * @param startTime
	 * @param endTime
	 */
	public DateTimePair(String date, String startTime, String endTime) {
		try {
			this.date = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse(date);
		} catch (ParseException exception) {
			exception.printStackTrace();
		}
		parseTime(startTime);
		parseTime(endTime);
	}

	/**
	 * Returns the value of the field called 'start'.
	 * @return Returns the start time.
	 */
	public Time getStartTime() {
		return this.start;
	}
	
	/**
	 * Returns the value of the field called 'end'.
	 * @return Returns the end time.
	 */
	public Time getEndTime() {
		return this.end;
	}
	
	/**
	 * Returns the value of the field called 'date'.
	 * @return Returns the date.
	 */
	public Date getDate() {
		return this.date;
	}

	private void parseTime(String time) {
//		time.split(":");
		int ind1 = time.indexOf(":");
		int ind2 = time.indexOf(" ");
		int hour = Integer.parseInt(time.substring(0, ind1));
		int minute = Integer.parseInt(time.substring(ind1+1, ind2));
		if (time.toLowerCase(Locale.ENGLISH).matches("pm")) {
			hour += 12;
		}
		this.start = new Time(hour, minute);
	}
}
