Skip to content

Commit

Permalink
Merge pull request #730 from jonbullock/fix/726-timezone
Browse files Browse the repository at this point in the history
Fixes #726 - Sets TimeZone for Freemarker template engine
  • Loading branch information
jonbullock authored Nov 16, 2021
2 parents 5a47ac1 + 95e2776 commit 7030731
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 7030731

Please sign in to comment.