Java tutorial
/** * The Clican-Pluto software suit is Copyright 2009, Clican Company and individual contributors, and is licensed under the GNU LGPL. * * @author clican * */ package com.clican.pluto.dataprocess.dpl.function.impl; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; import org.apache.commons.lang.time.DateUtils; import com.clican.pluto.dataprocess.dpl.parser.bean.PrefixAndSuffix; import com.clican.pluto.dataprocess.exception.CalculationException; import com.clican.pluto.dataprocess.exception.DplParseException; import com.clican.pluto.dataprocess.exception.PrefixAndSuffixException; /** * ,?21 * * @author clican * */ public class DayOfQuarter extends BaseSingleRowFunction { private PrefixAndSuffix date; public Object calculate(Map<String, Object> row) throws CalculationException, PrefixAndSuffixException { Date d = date.getValue(row); SimpleDateFormat sdf = new SimpleDateFormat("MMdd"); String s = sdf.format(d); if (s.compareTo("0321") < 0) { // 12 1 2 if (IsLeapYear.isLeapYear(d)) { return 91; } else { return 90; } } else if (s.compareTo("1221") >= 0) { // 12 1 2 if (IsLeapYear.isLeapYear(DateUtils.addYears(d, 1))) { return 91; } else { return 90; } } else if (s.compareTo("0921") >= 0) { // 9 10 11 return 91; } else if (s.compareTo("0621") >= 0) { // 6 7 8 return 92; } else { // 3 4 5 return 92; } } public boolean isSupportWhere() throws DplParseException { return true; } public void setParams(List<Object> params) throws DplParseException { super.setParams(params); this.date = pasList.get(0); } } // $Id: DayOfQuarter.java 12410 2010-05-13 06:55:57Z wei.zhang $