/*
 * Copyright (c) 2004, Rob Gordon.
 */
package org.treesched.schedules;

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

import org.treesched.Interval;
import org.treesched.schedules.DailySchedule;

import junit.framework.TestCase;

/**
 *
 * @author Rob Gordon.
 */
public class DailyScheduleTest extends TestCase {

    static DateFormat checkFormat = new SimpleDateFormat("dd-MMM-yy HH:mm:ss:SSS");
    static DateFormat inputFormat = new SimpleDateFormat("dd-MMM-yy HH:mm");
    
    public void testDaily() throws ParseException {
        DailySchedule schedule = new DailySchedule();
 
        Date now1 = inputFormat.parse("31-jan-2004 12:30");
        Interval expected = new Interval
                (checkFormat.parse("31-jan-2004 12:30:00:000"),
                 checkFormat.parse("01-feb-2004 12:29:59:999"));
        Interval actual = schedule.nextDue(now1);
        assertTrue("[" + actual+ "] wrong.", 
                expected.equals(actual));
    }
    
    public void testDailyFrom() throws ParseException {
        DailySchedule schedule = new DailySchedule();
        Interval limits = new Interval(inputFormat.parse("09-feb-2004 09:15"));
        schedule.setLimits(limits);
        Date now1 = inputFormat.parse("10-feb-2004 12:30");
        Interval expected = new Interval(
                checkFormat.parse("10-feb-2004 09:15:00:000"), 
                checkFormat.parse("11-feb-2004 09:14:59:999"));
        Interval actual = schedule.nextDue(now1);
        assertTrue("[" + actual + "] wrong.", expected.equals(actual));
    }
    
    public void testDailyTo() throws ParseException {
        DailySchedule schedule = new DailySchedule();
        Interval limits = new Interval(
                inputFormat.parse("09-feb-2004 09:15"),
                inputFormat.parse("11-feb-2004 04:00"));
        schedule.setLimits(limits);
        Date now1 = inputFormat.parse("10-feb-2004 12:30");
        Interval expected = new Interval(
                checkFormat.parse("10-feb-2004 09:15:00:000"), 
                checkFormat.parse("11-feb-2004 09:14:59:999"));
        Interval actual = schedule.nextDue(now1);
        assertTrue("[" + actual + "] wrong.", expected.equals(actual));
    }

    public void testDailyPast() throws ParseException {
        DailySchedule schedule = new DailySchedule();
        Interval limits = new Interval(
                inputFormat.parse("09-feb-2004 09:15"),
                inputFormat.parse("11-feb-2004 04:00"));
        schedule.setLimits(limits);
        Date now1 = inputFormat.parse("11-feb-2004 12:30");
        Interval expected = null;
        Interval actual = schedule.nextDue(now1);
        assertTrue("[" + actual + "] wrong.", expected == actual);
    }

    
    
}
