Skip to content

Commit

Permalink
Fixes #726
Browse files Browse the repository at this point in the history
Allows you to override the time zone used to display date and time in Freemarker templates.
  • Loading branch information
jonbullock committed Oct 18, 2021
1 parent cec1009 commit 95e2776
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,13 @@ public String getAbbreviatedGitHash() {
public String getJvmLocale() {
return getAsString(JVM_LOCALE.getKey());
}

@Override
public TimeZone getFreemarkerTimeZone() {
String timezone = getAsString(FREEMARKER_TIMEZONE.getKey());
if (StringUtils.isNotEmpty(timezone)) {
return TimeZone.getTimeZone(timezone);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;

/**
* JBakeConfiguration gives you access to the project configuration. Typically located in a file called jbake.properties.
Expand Down Expand Up @@ -367,6 +368,12 @@ public interface JBakeConfiguration {
*/
String getJvmLocale();

/**
*
* @return TimeZone to use within Freemarker
*/
TimeZone getFreemarkerTimeZone();

Map<String, Object> asHashMap();

List<Property> getJbakeProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public abstract class PropertyList {
"filename to use for feed"
);

public static final Property FREEMARKER_TIMEZONE = new Property(
"freemarker.timezone",
"TimeZone to use within Freemarker"
);

public static final Property GIT_HASH = new Property(
"git.hash",
"abbreviated git hash"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ private void createTemplateConfiguration() {
templateCfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
templateCfg.setDefaultEncoding(config.getRenderEncoding());
templateCfg.setOutputEncoding(config.getOutputEncoding());
if (config.getFreemarkerTimeZone() != null) {
templateCfg.setTimeZone(config.getFreemarkerTimeZone());
templateCfg.setSQLDateAndTimeTimeZone(config.getFreemarkerTimeZone());
}
try {
templateCfg.setDirectoryForTemplateLoading(config.getTemplateFolder());
} catch (IOException e) {
Expand Down

0 comments on commit 95e2776

Please sign in to comment.