Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MONDRIAN - added new CurrentDateString UDF
[git-p4: depot-paths = "//open/mondrian/": change = 7116]
- Loading branch information
Zelaine Fong
committed
Jul 5, 2006
1 parent
8257e51
commit c8b154e
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mondrian.udf.ValUdf | ||
mondrian.udf.InverseNormalUdf | ||
mondrian.udf.LastNonEmptyUdf | ||
mondrian.udf.CurrentDateStringUdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
// $Id$ | ||
// This software is subject to the terms of the Common Public License | ||
// Agreement, available at the following URL: | ||
// http://www.opensource.org/licenses/cpl.html. | ||
// Copyright (C) 2006-2006 Julian Hyde and others | ||
// All Rights Reserved. | ||
// You must accept the terms of that agreement to use this software. | ||
*/ | ||
package mondrian.udf; | ||
|
||
import mondrian.olap.Evaluator; | ||
import mondrian.olap.Syntax; | ||
import mondrian.olap.type.StringType; | ||
import mondrian.olap.type.Type; | ||
import mondrian.spi.UserDefinedFunction; | ||
import mondrian.util.*; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* User-defined function CurrentDateString, which returns the current date | ||
* value as a formatted string, based on a format string passed in as a | ||
* parameter. The format string conforms to the format string implemented | ||
* by {@link Format}. | ||
* | ||
* @author Zelaine Fong | ||
*/ | ||
public class CurrentDateStringUdf implements UserDefinedFunction { | ||
|
||
public Object execute(Evaluator evaluator, Argument[] arguments) { | ||
Object arg = arguments[0].evaluateScalar(evaluator); | ||
|
||
if (!(arg instanceof String)) { | ||
return null; | ||
} | ||
final Locale locale = Locale.getDefault(); | ||
final Format format = new Format((((String) arg).toString()), locale); | ||
Date currDate = new Date(); | ||
return format.format(currDate); | ||
} | ||
|
||
public String getDescription() { | ||
return "Returns current date as a formatted string"; | ||
} | ||
|
||
public String getName() { | ||
return "CurrentDateString"; | ||
} | ||
|
||
public Type[] getParameterTypes() { | ||
return new Type[] { new StringType() }; | ||
} | ||
|
||
public String[] getReservedWords() { | ||
return null; | ||
} | ||
|
||
public Type getReturnType(Type[] parameterTypes) { | ||
return new StringType(); | ||
} | ||
|
||
public Syntax getSyntax() { | ||
return Syntax.Function; | ||
} | ||
|
||
} | ||
|
||
// End CurrentDateStringUdf.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters