View Javadoc

1   /*
2    * $Id: Ms2hourFunction.java 1419 2010-11-01 14:12:17Z hoheisel $
3    *
4    * Copyright (c) 2005, The K-Wf Grid Consortium
5    * Fraunhofer Institute for Computer Architecture and Software Technology
6    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
7    */
8   
9   package net.kwfgrid.gwes.jaxen;
10  
11  import org.jaxen.Function;
12  import org.jaxen.Context;
13  import org.jaxen.FunctionCallException;
14  import org.jaxen.function.NumberFunction;
15  
16  import java.util.List;
17  import java.util.Calendar;
18  
19  /**
20   * Converts date time in Milliseconds from 1970 to Double, representing the hour of day.
21   * Input: Double, output: Double.
22   * Important: returns hour for local time zone!
23   * @author Andreas Hoheisel
24   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
25   * @version $Id: Ms2hourFunction.java 1419 2010-11-01 14:12:17Z hoheisel $
26   */
27  public class Ms2hourFunction implements Function {
28  
29      public Object call(Context context, List args) throws FunctionCallException {
30          if (args.isEmpty()) throw new FunctionCallException("Argument missing.");
31          if (args.size() > 1) throw new FunctionCallException("Too many arguments.");
32          Double dms = (Double)args.get(0);
33          long ms = dms.longValue();
34          TimeScheme time = new TimeScheme(ms);
35          Integer ivalue = time.getCal().get(Calendar.HOUR_OF_DAY);
36          return ivalue.doubleValue();
37      }
38  
39  }