All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.camunda.bpm.engine.impl.calendar.DurationBusinessCalendar Maven / Gradle / Ivy

There is a newer version: 7.23.0-alpha2
Show newest version
/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.camunda.bpm.engine.impl.calendar;

import java.util.Date;

import org.camunda.bpm.engine.ProcessEngineException;


/**
 * @author Tom Baeyens
 */
public class DurationBusinessCalendar implements BusinessCalendar {
  
  public static String NAME = "duration";

  public Date resolveDuedate(String duedate) {
    try {
      DurationHelper dh = new DurationHelper(duedate);
      return dh.getDateAfter();
    } catch (Exception e) {
      throw new ProcessEngineException("couldn't resolve duedate: "+e.getMessage(), e);
    }
  }
    
// Code below just left in for a while just in case it would be needed again.
//  
//  private static Map units = new HashMap();
//  static {
//    units.put("millis", Calendar.MILLISECOND);
//    units.put("seconds", Calendar.SECOND);
//    units.put("second", Calendar.SECOND);
//    units.put("minute", Calendar.MINUTE);
//    units.put("minutes", Calendar.MINUTE);
//    units.put("hour", Calendar.HOUR);
//    units.put("hours", Calendar.HOUR);
//    units.put("day", Calendar.DAY_OF_YEAR);
//    units.put("days", Calendar.DAY_OF_YEAR);
//    units.put("week", Calendar.WEEK_OF_YEAR);
//    units.put("weeks", Calendar.WEEK_OF_YEAR);
//    units.put("month", Calendar.MONTH);
//    units.put("months", Calendar.MONTH);
//    units.put("year", Calendar.YEAR);
//    units.put("years", Calendar.YEAR);
//  }
//  
//  public Date resolveDuedate(String duedate) {
//    Date resolvedDuedate = Clock.getCurrentTime();
//    
//    StringTokenizer tokenizer = new StringTokenizer(duedate, " and ");
//    while (tokenizer.hasMoreTokens()) {
//      String singleUnitQuantity = tokenizer.nextToken();
//      resolvedDuedate = addSingleUnitQuantity(resolvedDuedate, singleUnitQuantity);
//    }
//    
//    return resolvedDuedate;
//  }
//
//  protected Date addSingleUnitQuantity(Date startDate, String singleUnitQuantity) {
//    int spaceIndex = singleUnitQuantity.indexOf(' ');
//    if (spaceIndex==-1 || singleUnitQuantity.length() > spaceIndex+1) {
//      throw new ProcessEngineException("invalid duedate format: "+singleUnitQuantity);
//    }
//    
//    String quantityText = singleUnitQuantity.substring(0, spaceIndex);
//    Integer quantity = new Integer(quantityText);
//    
//    String unitText = singleUnitQuantity
//      .substring(spaceIndex+1)
//      .trim()
//      .toLowerCase();
//    
//    int unit = units.get(unitText);
//
//    GregorianCalendar calendar = new GregorianCalendar(); 
//    calendar.setTime(startDate);
//    calendar.add(unit, quantity);
//    
//    return calendar.getTime();
//  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy