mirror of
https://github.com/octoleo/plantuml.git
synced 2024-12-22 02:49:06 +00:00
Adding %now function
This commit is contained in:
parent
ebf7613792
commit
9371ad88dc
@ -113,6 +113,7 @@ import net.sourceforge.plantuml.tim.stdlib.LoadJson;
|
|||||||
import net.sourceforge.plantuml.tim.stdlib.LogicalNot;
|
import net.sourceforge.plantuml.tim.stdlib.LogicalNot;
|
||||||
import net.sourceforge.plantuml.tim.stdlib.Lower;
|
import net.sourceforge.plantuml.tim.stdlib.Lower;
|
||||||
import net.sourceforge.plantuml.tim.stdlib.Newline;
|
import net.sourceforge.plantuml.tim.stdlib.Newline;
|
||||||
|
import net.sourceforge.plantuml.tim.stdlib.Now;
|
||||||
import net.sourceforge.plantuml.tim.stdlib.RetrieveProcedure;
|
import net.sourceforge.plantuml.tim.stdlib.RetrieveProcedure;
|
||||||
import net.sourceforge.plantuml.tim.stdlib.ReverseColor;
|
import net.sourceforge.plantuml.tim.stdlib.ReverseColor;
|
||||||
import net.sourceforge.plantuml.tim.stdlib.ReverseHsluvColor;
|
import net.sourceforge.plantuml.tim.stdlib.ReverseHsluvColor;
|
||||||
@ -189,6 +190,7 @@ public class TContext {
|
|||||||
functionsSet.addFunction(new GetJsonType());
|
functionsSet.addFunction(new GetJsonType());
|
||||||
functionsSet.addFunction(new SplitStr());
|
functionsSet.addFunction(new SplitStr());
|
||||||
functionsSet.addFunction(new JsonKeyExists());
|
functionsSet.addFunction(new JsonKeyExists());
|
||||||
|
functionsSet.addFunction(new Now());
|
||||||
// %standard_exists_function
|
// %standard_exists_function
|
||||||
// %str_replace
|
// %str_replace
|
||||||
// !exit
|
// !exit
|
||||||
|
@ -51,21 +51,26 @@ import net.sourceforge.plantuml.tim.expression.TValue;
|
|||||||
public class DateFunction extends SimpleReturnFunction {
|
public class DateFunction extends SimpleReturnFunction {
|
||||||
|
|
||||||
public TFunctionSignature getSignature() {
|
public TFunctionSignature getSignature() {
|
||||||
return new TFunctionSignature("%date", 1);
|
return new TFunctionSignature("%date", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canCover(int nbArg, Set<String> namedArgument) {
|
public boolean canCover(int nbArg, Set<String> namedArgument) {
|
||||||
return nbArg == 0 || nbArg == 1;
|
return nbArg == 0 || nbArg == 1 || nbArg == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
|
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
|
||||||
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
|
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
|
||||||
if (values.size() == 0) {
|
if (values.size() == 0)
|
||||||
return TValue.fromString(new Date().toString());
|
return TValue.fromString(new Date().toString());
|
||||||
}
|
|
||||||
final String format = values.get(0).toString();
|
final String format = values.get(0).toString();
|
||||||
|
final long now;
|
||||||
|
if (values.size() == 2)
|
||||||
|
now = 1000L * values.get(1).toInt();
|
||||||
|
else
|
||||||
|
now = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
return TValue.fromString(new SimpleDateFormat(format).format(new Date()));
|
return TValue.fromString(new SimpleDateFormat(format).format(now));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw EaterException.unlocated("Bad date pattern");
|
throw EaterException.unlocated("Bad date pattern");
|
||||||
}
|
}
|
||||||
|
64
src/net/sourceforge/plantuml/tim/stdlib/Now.java
Normal file
64
src/net/sourceforge/plantuml/tim/stdlib/Now.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/* ========================================================================
|
||||||
|
* PlantUML : a free UML diagram generator
|
||||||
|
* ========================================================================
|
||||||
|
*
|
||||||
|
* (C) Copyright 2009-2023, Arnaud Roques
|
||||||
|
*
|
||||||
|
* Project Info: http://plantuml.com
|
||||||
|
*
|
||||||
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
|
*
|
||||||
|
* http://plantuml.com/patreon (only 1$ per month!)
|
||||||
|
* http://plantuml.com/paypal
|
||||||
|
*
|
||||||
|
* This file is part of PlantUML.
|
||||||
|
*
|
||||||
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PlantUML distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Original Author: Arnaud Roques
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.sourceforge.plantuml.tim.stdlib;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.LineLocation;
|
||||||
|
import net.sourceforge.plantuml.tim.EaterException;
|
||||||
|
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
|
||||||
|
import net.sourceforge.plantuml.tim.TContext;
|
||||||
|
import net.sourceforge.plantuml.tim.TFunctionSignature;
|
||||||
|
import net.sourceforge.plantuml.tim.TMemory;
|
||||||
|
import net.sourceforge.plantuml.tim.expression.TValue;
|
||||||
|
|
||||||
|
public class Now extends SimpleReturnFunction {
|
||||||
|
|
||||||
|
public TFunctionSignature getSignature() {
|
||||||
|
return new TFunctionSignature("%now", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canCover(int nbArg, Set<String> namedArgument) {
|
||||||
|
return nbArg == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
|
||||||
|
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
|
||||||
|
final long now = System.currentTimeMillis() / 1000L;
|
||||||
|
return TValue.fromInt((int) now);
|
||||||
|
}
|
||||||
|
}
|
@ -80,7 +80,7 @@ public class Version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int beta() {
|
public static int beta() {
|
||||||
final int beta = 3;
|
final int beta = 4;
|
||||||
return beta;
|
return beta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user