001 /* 002 // $Id: //open/mondrian/src/main/mondrian/udf/CurrentDateStringUdf.java#6 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2006-2007 Julian Hyde and others 007 // All Rights Reserved. 008 // You must accept the terms of that agreement to use this software. 009 */ 010 package mondrian.udf; 011 012 import mondrian.olap.Evaluator; 013 import mondrian.olap.Syntax; 014 import mondrian.olap.type.StringType; 015 import mondrian.olap.type.Type; 016 import mondrian.spi.UserDefinedFunction; 017 import mondrian.util.*; 018 019 import java.util.*; 020 021 /** 022 * User-defined function <code>CurrentDateString<code>, which returns the 023 * current date value as a formatted string, based on a format string passed in 024 * as a parameter. The format string conforms to the format string implemented 025 * by {@link Format}. 026 * 027 * @author Zelaine Fong 028 * @version $Id: //open/mondrian/src/main/mondrian/udf/CurrentDateStringUdf.java#6 $ 029 */ 030 public class CurrentDateStringUdf implements UserDefinedFunction { 031 032 public Object execute(Evaluator evaluator, Argument[] arguments) { 033 Object arg = arguments[0].evaluateScalar(evaluator); 034 035 final Locale locale = Locale.getDefault(); 036 final Format format = new Format((String) arg, locale); 037 Date currDate = evaluator.getQueryStartTime(); 038 return format.format(currDate); 039 } 040 041 public String getDescription() { 042 return "Returns the current date formatted as specified by the format parameter."; 043 } 044 045 public String getName() { 046 return "CurrentDateString"; 047 } 048 049 public Type[] getParameterTypes() { 050 return new Type[] { new StringType() }; 051 } 052 053 public String[] getReservedWords() { 054 return null; 055 } 056 057 public Type getReturnType(Type[] parameterTypes) { 058 return new StringType(); 059 } 060 061 public Syntax getSyntax() { 062 return Syntax.Function; 063 } 064 065 } 066 067 // End CurrentDateStringUdf.java