/* 
 * Copyright (C) 2015 Christophe
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

package com.doubotis.restwrapper.servlet;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author Christophe
 */
public class ProcessDuration
{
    Date mDateStart = null;
    Date mDateEnd = null;
    
    public ProcessDuration(Date dateStart, Date dateEnd)
    {
        mDateStart = dateStart;
        mDateEnd = dateEnd;
    }
    
    public ProcessDuration() {}
    
    public void setStartDate(Date dateStart)
    {
        mDateStart = dateStart;
    }
    
    public void setEndDate(Date dateEnd)
    {
        mDateEnd = dateEnd;
    }
    
    public long getDurationTimestamp(TimeUnit timeUnit)
    {
        if (mDateStart == null || mDateEnd == null) throw new IllegalStateException("Start and End dates must be defined");
        long diffInMillies = mDateEnd.getTime() - mDateStart.getTime();
        return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS);
    }
    
    
    
}
