11package com .hubspot .jinjava .lib .filter ;
22
3+ import static com .hubspot .jinjava .lib .filter .time .DateTimeFormatHelper .FIXED_DATE_TIME_FILTER_NULL_ARG ;
4+
35import com .hubspot .jinjava .doc .annotations .JinjavaDoc ;
46import com .hubspot .jinjava .doc .annotations .JinjavaParam ;
57import com .hubspot .jinjava .doc .annotations .JinjavaSnippet ;
8+ import com .hubspot .jinjava .features .DateTimeFeatureActivationStrategy ;
9+ import com .hubspot .jinjava .features .FeatureActivationStrategy ;
10+ import com .hubspot .jinjava .interpret .InvalidArgumentException ;
611import com .hubspot .jinjava .interpret .JinjavaInterpreter ;
12+ import com .hubspot .jinjava .interpret .TemplateError ;
713import com .hubspot .jinjava .lib .fn .Functions ;
814
915@ JinjavaDoc (
1016 value = "Gets the UNIX timestamp value (in milliseconds) of a date object" ,
11- input = @ JinjavaParam (
12- value = "value" ,
13- defaultValue = "current time" ,
14- desc = "The date variable" ,
15- required = true
16- ),
17+ input = @ JinjavaParam (value = "value" , desc = "The date variable" , required = true ),
1718 snippets = { @ JinjavaSnippet (code = "{% mydatetime|unixtimestamp %}" ) }
1819)
1920public class UnixTimestampFilter implements Filter {
@@ -25,6 +26,27 @@ public String getName() {
2526
2627 @ Override
2728 public Object filter (Object var , JinjavaInterpreter interpreter , String ... args ) {
29+ if (var == null ) {
30+ interpreter .addError (
31+ TemplateError .fromMissingFilterArgException (
32+ new InvalidArgumentException (
33+ interpreter ,
34+ "unixtimestamp" ,
35+ "unixtimestamp filter called with null datetime"
36+ )
37+ )
38+ );
39+
40+ FeatureActivationStrategy feat = interpreter
41+ .getConfig ()
42+ .getFeatures ()
43+ .getActivationStrategy (FIXED_DATE_TIME_FILTER_NULL_ARG );
44+
45+ if (feat .isActive (interpreter .getContext ())) {
46+ var = ((DateTimeFeatureActivationStrategy ) feat ).getActivateAt ();
47+ }
48+ }
49+
2850 return Functions .unixtimestamp (var );
2951 }
3052}
0 commit comments