View Javadoc

1   /*
2    * $Id: Ms2yearFunction.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  
15  import java.util.List;
16  import java.util.Calendar;
17  
18  /**
19   * Converts date time in Milliseconds from 1970 to Double, representing the year.
20   * Input: Double, output: Double.
21   * @author Andreas Hoheisel
22   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
23   * @version $Id: Ms2yearFunction.java 1419 2010-11-01 14:12:17Z hoheisel $
24   */
25  public class Ms2yearFunction implements Function {
26  
27      public Object call(Context context, List args) throws FunctionCallException {
28          if (args.isEmpty()) throw new FunctionCallException("Argument missing.");
29          if (args.size() > 1) throw new FunctionCallException("Too many arguments.");
30          Double dms = (Double)args.get(0);
31          long ms = dms.longValue();
32          TimeScheme time = new TimeScheme(ms);
33          Integer ivalue = time.getCal().get(Calendar.YEAR);
34          return ivalue.doubleValue();
35      }
36  
37  }