/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE file.
 */
package org.apache.avalon.db.functions.impl;

import org.apache.avalon.db.data.Row;
import org.apache.avalon.db.data.types.StringColumn;
import org.apache.avalon.db.data.types.TemporalColumn;

import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Class CurrentDateTemporalFunction
 *
 * @author Larry McCay <a href="mailto:lawrence_mccay-iii@hp.com">lawrence_mccay-iii@hp.com</a>
 * @version $Revision: 1.1 $
 */
public class DayNameTemporalFunction extends AbstractTemporalStringFunction {

   final String[] mDaysOfWeek  = {"Sunday",
                                 "Monday",
                                 "Tuesday",
                                 "Wednesday",
                                 "Thursday",
                                 "Friday",
                                 "Saturday"
                                 };

    public DayNameTemporalFunction() {
       super(9);
    }

   public int getMaxLength()
   {
      return 9;
   }

    public String getStringValue(Row row) {
       TemporalColumn tc = (TemporalColumn) mColumns[0];
       Date date = (Date) tc.getValue(row);
       mGregorianCalendar.setTime(date);

       int dayofweek = mGregorianCalendar.get(Calendar.DAY_OF_WEEK);

       return mDaysOfWeek[ dayofweek - 1];
    }

   /**
    * Method getMinCols
    *
    *
    * @return
    *
    */
   public int getMinCols() {
       return 1;
   }

   /**
    * Method getMaxCols
    *
    *
    * @return
    *
    */
   public int getMaxCols() {
       return 1;
   }
}
