unix_time and convert_date (#332)
* very simple stuff * added unix_date and imporved unix_time * Update docs/scarpet/api/Auxiliary.md Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com> * Update Full.md * Dont 100% work, but It'll do untl I fix tomorrow * works, I think * changeing weekdays * removing weird stuff I didnt mean to do * previous commits * moving to expression.java because prof.gnembon said * moving away from LazyFUnctions cos gnembon doesn't like evaluating somewhere * updating docs * tweaks to dates Co-authored-by: Ghoulboy78 <ghoulboy27@gmail.com>
This commit is contained in:
1 parent
b77268553e
commit
29a81d53d6
5 files changed
+162
No files matched your search
@@ -43,7 +43,9 @@ import org.apache.commons.lang3.text.WordUtils;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.IllegalFormatException;
|
||||
import java.util.Iterator;
|
||||
@@ -1790,6 +1792,66 @@ public class Expression
|
||||
return (cc, tt) -> time;
|
||||
});
|
||||
|
||||
addLazyFunction("unix_time", 0, (c, t, lv) ->
|
||||
{
|
||||
Value time = new NumericValue(System.currentTimeMillis());
|
||||
return (cc, tt) -> time;
|
||||
});
|
||||
|
||||
addFunction("convert_date", lv ->
|
||||
{
|
||||
int argsize = lv.size();
|
||||
if (lv.size() == 0) throw new InternalExpressionException("'convert_date' requires at least one parameter");
|
||||
Value value = lv.get(0);
|
||||
if (argsize == 1 && !(value instanceof ListValue))
|
||||
{
|
||||
Calendar cal = new GregorianCalendar(Locale.ROOT);
|
||||
cal.setTimeInMillis(NumericValue.asNumber(value, "timestamp").getLong());
|
||||
int weekday = cal.get(Calendar.DAY_OF_WEEK)-1;
|
||||
if (weekday == 0) weekday = 7;
|
||||
Value retVal = ListValue.ofNums(
|
||||
cal.get(Calendar.YEAR),
|
||||
cal.get(Calendar.MONTH)+1,
|
||||
cal.get(Calendar.DAY_OF_MONTH),
|
||||
cal.get(Calendar.HOUR_OF_DAY),
|
||||
cal.get(Calendar.MINUTE),
|
||||
cal.get(Calendar.SECOND),
|
||||
weekday,
|
||||
cal.get(Calendar.DAY_OF_YEAR),
|
||||
cal.get(Calendar.WEEK_OF_YEAR)
|
||||
);
|
||||
return retVal;
|
||||
}
|
||||
else if(value instanceof ListValue)
|
||||
{
|
||||
lv = ((ListValue) value).getItems();
|
||||
argsize = lv.size();
|
||||
}
|
||||
Calendar cal = new GregorianCalendar(0, 0, 0, 0, 0, 0);
|
||||
|
||||
if (argsize == 3)
|
||||
{
|
||||
cal.set(
|
||||
NumericValue.asNumber(lv.get(0)).getInt(),
|
||||
NumericValue.asNumber(lv.get(1)).getInt()-1,
|
||||
NumericValue.asNumber(lv.get(2)).getInt()
|
||||
);
|
||||
}
|
||||
else if (argsize == 6)
|
||||
{
|
||||
cal.set(
|
||||
NumericValue.asNumber(lv.get(0)).getInt(),
|
||||
NumericValue.asNumber(lv.get(1)).getInt()-1,
|
||||
NumericValue.asNumber(lv.get(2)).getInt(),
|
||||
NumericValue.asNumber(lv.get(3)).getInt(),
|
||||
NumericValue.asNumber(lv.get(4)).getInt(),
|
||||
NumericValue.asNumber(lv.get(5)).getInt()
|
||||
);
|
||||
}
|
||||
else throw new InternalExpressionException("Date conversion requires 3 arguments for Dates or 6 arguments, for time");
|
||||
return new NumericValue(cal.getTimeInMillis());
|
||||
});
|
||||
|
||||
addLazyFunction("profile_expr", 1, (c, t, lv) ->
|
||||
{
|
||||
LazyValue lazy = lv.get(0);
|
||||
|
||||
Reference in new issue
Block a user