Example #1
0
// Returns the closest interval on the same day to the given interval.
func (e *Entries) GetClosest(a iface.Filter, data map[string]interface{}) (*evenday.Interval, error) {
	e.getOptions(a.Subject())
	prof, err := e.db.ToId(data["professional"].(string))
	if err != nil {
		return nil, err
	}
	from := data["from"].(int64)
	length := data["length"].(int64)
	err = e.intervalIsValid(data, prof, length)
	if err != nil {
		return nil, err
	}
	tt, err := e.getTimeTable(prof)
	if err != nil {
		return nil, err
	}
	day := evenday.DateToDayName(from)
	open := tt[day]
	taken, err := e.getTaken(a, from)
	if err != nil {
		return nil, err
	}
	adv := evenday.NewAdvisor(open, taken)
	to := from + length*60
	adv.Amount(1)
	interv, err := evenday.NewInterval(evenday.DateToMinute(from), evenday.DateToMinute(to))
	if err != nil {
		return nil, err
	}
	ret := adv.Advise(interv)
	if len(ret) == 0 {
		return nil, fmt.Errorf("Can't advise you, all day is taken.")
	}
	return ret[0], nil
}
Example #2
0
// Checks if the timeTable is ok and the interval fits into the timeTable.
func (e *Entries) okAccordingToTimeTable(data map[string]interface{}, from, to int64) error {
	dayN := evenday.DateToDayName(from)
	prof, err := e.db.ToId(data["professional"].(string))
	if err != nil {
		return err
	}
	interval, err := evenday.GenericToInterval(from, to)
	if err != nil {
		return err
	}
	timeTable, err := e.getTimeTable(prof)
	if err != nil {
		return err
	}
	if !evenday.InTimeTable(dayN, interval, timeTable) {
		return fmt.Errorf("Interval does not fit into timeTable.")
	}
	return nil
}