Added new special variable, time_zone (referred like .time_zone, like all special variables), to retrieve the current value of the time_zone setting as a string.
diff --git a/src/main/java/freemarker/core/BuiltinVariable.java b/src/main/java/freemarker/core/BuiltinVariable.java
index b5ec4b7..ccc9d0b 100644
--- a/src/main/java/freemarker/core/BuiltinVariable.java
+++ b/src/main/java/freemarker/core/BuiltinVariable.java
@@ -56,6 +56,8 @@
static final String LOCALE = Configurable.LOCALE_KEY;
static final String LOCALE_OBJECT_CC = Configurable.LOCALE_KEY_CAMEL_CASE + "Object";
static final String LOCALE_OBJECT = Configurable.LOCALE_KEY + "_object";
+ static final String TIME_ZONE_CC = Configurable.TIME_ZONE_KEY_CAMEL_CASE;
+ static final String TIME_ZONE = Configurable.TIME_ZONE_KEY;
static final String CURRENT_NODE_CC = "currentNode";
static final String CURRENT_NODE = "current_node";
static final String NODE = "node";
@@ -116,6 +118,8 @@
PASS,
TEMPLATE_NAME_CC,
TEMPLATE_NAME,
+ TIME_ZONE_CC,
+ TIME_ZONE,
URL_ESCAPING_CHARSET_CC,
URL_ESCAPING_CHARSET,
VARS,
@@ -270,6 +274,9 @@
}
return args;
}
+ if (name == TIME_ZONE || name == TIME_ZONE_CC) {
+ return new SimpleScalar(env.getTimeZone().getID());
+ }
throw new _MiscTemplateException(this,
"Invalid special variable: ", name);
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index b6682b9..8ef2763 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -25469,6 +25469,18 @@
contains dash and further info after the numbers, like in
2.3.21-nightly_20140726T151800Z.</para>
</listitem>
+
+ <listitem>
+ <para><indexterm>
+ <primary>time zone</primary>
+ </indexterm><indexterm>
+ <primary>time_zone</primary>
+ </indexterm><literal>time_zone</literal> (exists since FreeMarker
+ 2.3.31): The current value of the <literal>time_zone</literal>
+ setting, as a string. This is the ID of the time zone, like
+ <literal>GMT+01:00</literal>, or
+ <literal>America/Los_Angeles</literal>.</para>
+ </listitem>
</itemizedlist>
<simplesect xml:id="ref_specvar_get_optional_template">
@@ -29419,6 +29431,13 @@
</listitem>
<listitem>
+ <para>Added new special variable, <literal>time_zone</literal>
+ (referred like <literal>.time_zone</literal>, like all special
+ variables), to retrieve the current value of the
+ <literal>time_zone</literal> setting as a string.</para>
+ </listitem>
+
+ <listitem>
<para>Allowed escaping <literal>#</literal> with backlash in
identifier names (not in string), as it used to occur in
database column names. Like if you have a column name like
diff --git a/src/test/java/freemarker/core/CamelCaseTest.java b/src/test/java/freemarker/core/CamelCaseTest.java
index b1e1dcd..4e5d537 100644
--- a/src/test/java/freemarker/core/CamelCaseTest.java
+++ b/src/test/java/freemarker/core/CamelCaseTest.java
@@ -25,6 +25,7 @@
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
+import java.util.TimeZone;
import org.junit.Test;
@@ -43,6 +44,8 @@
assertOutput("${.data_model?is_hash?c}", "true");
assertOutput("${.localeObject.toString()}", "de_DE");
assertOutput("${.locale_object.toString()}", "de_DE");
+ assertOutput("${.time_zone}", getConfiguration().getTimeZone().getID());
+ assertOutput("${.timeZone}", getConfiguration().getTimeZone().getID());
assertOutput("${.templateName?length}", "0");
assertOutput("${.template_name?length}", "0");
assertOutput("${.outputEncoding}", "utf-8");
diff --git a/src/test/resources/freemarker/test/templatesuite/expected/specialvars.txt b/src/test/resources/freemarker/test/templatesuite/expected/specialvars.txt
index e2fa13e..2c7bac3 100644
--- a/src/test/resources/freemarker/test/templatesuite/expected/specialvars.txt
+++ b/src/test/resources/freemarker/test/templatesuite/expected/specialvars.txt
@@ -18,6 +18,7 @@
*/
en == en
en_US == en_US
+GMT+01:00 == GMT+01:00
utf-8 == utf-8
specialvars.ftl == specialvars.ftl
iso-8859-1 == iso-8859-1
diff --git a/src/test/resources/freemarker/test/templatesuite/templates/setting.ftl b/src/test/resources/freemarker/test/templatesuite/templates/setting.ftl
index fcf9605..715bbe2 100644
--- a/src/test/resources/freemarker/test/templatesuite/templates/setting.ftl
+++ b/src/test/resources/freemarker/test/templatesuite/templates/setting.ftl
@@ -37,8 +37,10 @@
<@assertEquals expected='dtf' actual=.now?string />
<#setting time_zone='GMT+00'>
+<@assertEquals expected='GMT+00:00' actual=.time_zone />
<#assign t1='2000'?datetime('yyyy')>
<#setting time_zone='GMT+01'>
+<@assertEquals expected='GMT+01:00' actual=.time_zone />
<#assign t2='2000'?datetime('yyyy')>
<@assertEquals expected=1000*60*60 actual=t1?long-t2?long />
diff --git a/src/test/resources/freemarker/test/templatesuite/templates/specialvars.ftl b/src/test/resources/freemarker/test/templatesuite/templates/specialvars.ftl
index 50416c9..abf53df 100644
--- a/src/test/resources/freemarker/test/templatesuite/templates/specialvars.ftl
+++ b/src/test/resources/freemarker/test/templatesuite/templates/specialvars.ftl
@@ -26,6 +26,7 @@
<#assign works = .globals>
${.lang} == en
${.locale} == en_US
+${.time_zone} == GMT+01:00
<#assign works = .locals!>
<#assign works = .main>
<#assign works = .node!>