package models;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.OneToMany;

import play.data.validation.Required;
import play.db.jpa.Model;

@SuppressWarnings("serial")
@Entity
public class TemporarySlot extends Model {
	
	@Field("startDate")
	@Required
	public Date startDate;
	
	@Field("endDate")
	@Required
	public Date endDate;
	
	@Field("labelEN")
	public String labelEN;
	@Field("labelFR")
	public String labelFR;
	
	@Override
	public String toString() {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
		
		StringBuffer strbuf = new StringBuffer();
		
		strbuf.append(dateFormat.format(startDate))
		      .append(" [")
		      .append(timeFormat.format(startDate))
			  .append(" - ")
			  .append(timeFormat.format(endDate))
			  .append("]");

		strbuf.append(" " + labelEN);
		
		return strbuf.toString();
	}
	
	public static List<Slot> findPerDay(Date day){
		return find("date_trunc('day', startDate) = ?1 ORDER BY startDate", day).fetch();
	}
	
}
package models;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.OneToMany;

import play.data.validation.Required;
import play.db.jpa.Model;

@SuppressWarnings("serial")
@Entity
public class TemporarySlot extends Model {
	
	@Field("startDate")
	@Required
	public Date startDate;
	
	@Field("endDate")
	@Required
	public Date endDate;
	
	@Field("labelEN")
	public String labelEN;
	@Field("labelFR")
	public String labelFR;
	
	@Required
	@Enumerated(EnumType.STRING)
	public BreakType isBreak;

	@Override
	public String toString() {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
		
		StringBuffer strbuf = new StringBuffer();
		
		strbuf.append(dateFormat.format(startDate))
		      .append(" [")
		      .append(timeFormat.format(startDate))
			  .append(" - ")
			  .append(timeFormat.format(endDate))
			  .append("]");

		strbuf.append(" " + labelEN);
		
		if (isBreak != null) {
			strbuf.append(" (" + isBreak.getCode() + ")");
		}

		return strbuf.toString();
	}
	
	public static List<Slot> findPerDay(Date day){
		return find("date_trunc('day', startDate) = ?1 ORDER BY startDate", day).fetch();
	}
	
}
Add breaks in TemporarySlot