Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #726 - Sets TimeZone for Freemarker template engine #730

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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