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

Migrate away from SimpleDateFormat #748

Open
bmarwell opened this issue Feb 11, 2022 · 4 comments
Open

Migrate away from SimpleDateFormat #748

bmarwell opened this issue Feb 11, 2022 · 4 comments

Comments

@bmarwell
Copy link

Hi,

the current default date format is yyyy-MM-dd.
However, I need time information to create a valid atom feed.

That said, SimpleDateFormat does not allow timezone information like 2022-01-01T21:20:40[Europe/Berlin].
The offset it provides might be ambiguous, so the actual timezone name is needed for calculations.

Proposal to:

  • Migrate to java.time.ZonedDateTime
  • If at all, use java.time.DateTimeFormatter
  • do not set the default timezone format (use ZonedDateTime.parse(String)) or set it to something like the default or yyyy-MM-dd HH:mm:ss[V]
  • If set to the latter, allow multiple patterns

the default templates should reflect this and use post.published_date?datetime?string.iso (without zone conversion) where possible and post.published_date?datetime?string.iso_utc where feasible (e.g. in machine-readable data).

@bmarwell
Copy link
Author

This is actually a follow-up of #726.

We solved it in shiro by using maven and forcing the JVM to use UTC:
https://github.com/apache/shiro-site/blob/983a971fb6478aea0520382978596155d44ca0b9/.mvn/jvm.config

It is not a nice solution. The reason this happens is that Date() will always add time information, even when none is given.

@bmarwell
Copy link
Author

Addendum:

  • If no time zone id or even time is given, UTC is a better assumption than the JVM's setting.
  • rendering UTC makes also sense, unless explicitly specified. Otherwise the displayed time or system readable time will change depending on who on the team bakes the site. Although the exact point in time is the same, it is hardly wanted to switch representations every now and then.

@jonbullock
Copy link
Member

Should be fairly straight forward to alter the code that parse the date to use something other than SimpleDateFormat.

Quick check suggests changes would be needed in MarkupEngine and AsciidoctorEngine, maybe elsewhere too.

Ideally java.util.Date would be replaced, due to the problems it causes, however this requires the template engines to support the replacement too.

@bmarwell
Copy link
Author

If you like, I can start a PR about this. I know Freemarker can cope with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants