freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geoffrey De Smet (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (FREEMARKER-35) Official JSR 310 support
Date Fri, 20 Jan 2017 10:17:26 GMT

    [ https://issues.apache.org/jira/browse/FREEMARKER-35?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15831507#comment-15831507
] 

Geoffrey De Smet edited comment on FREEMARKER-35 at 1/20/17 10:16 AM:
----------------------------------------------------------------------

Thanks for taking a look at this :)

I think you only need 1 new class: TemporalTemplateModel (or TemporalAccessorTemplateModel),
not 12+.

All those 12+ java.time objects implement the interface Temporal and TemporalAccessor.
For example, LocalDate implements Temporal and TemporalAccessor
DateTimeFormatter is the class to parse and format (so read and write) any of those 12 temporal
types.

Writing any such type is easy with DateTimeFormatter.format(TemporalAccessor):

{code}
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")
// Landed on moon on 1969-07-20
String s1 = "Landed on moon on " + dateTimeFormatter.format(LocalDate.of(1969,7,20));
// Landed on moon at 1969-07-20 20:18
String s2 = "Landed on moon at " + dateTimeFormatter.format(LocalDateTime.of(1969,7,20,20,18);
{code}

https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html

https://docs.oracle.com/javase/8/docs/api/java/time/temporal/Temporal.html

https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html


was (Author: ge0ffrey):
I think you only need 1 new class: TemporalTemplateModel (or TemporalAccessorTemplateModel),
not 12+.

All those 12+ java.time objects implement the interface Temporal and TemporalAccessor.
For example, LocalDate implements Temporal and TemporalAccessor
DateTimeFormatter is the class to parse and format (so read and write) any of those 12 temporal
types.

Writing any such type is easy with DateTimeFormatter.format(TemporalAccessor):

{code}
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")
// Landed on moon on 1969-07-20
String s1 = "Landed on moon on " + dateTimeFormatter.format(LocalDate.of(1969,7,20));
// Landed on moon at 1969-07-20 20:18
String s2 = "Landed on moon at " + dateTimeFormatter.format(LocalDateTime.of(1969,7,20,20,18);
{code}

https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html

https://docs.oracle.com/javase/8/docs/api/java/time/temporal/Temporal.html

https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

> Official JSR 310 support
> ------------------------
>
>                 Key: FREEMARKER-35
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-35
>             Project: Apache Freemarker
>          Issue Type: Improvement
>          Components: engine
>            Reporter: Tokuhiro Matsuno
>            Priority: Minor
>
> I suggest to implement an official JSR 310 support on freemarker.
> I know there's amedia's great freemarker-java-8.
> But if there's an official support, user can use freemarker more easily.
> ref. https://github.com/amedia/freemarker-java-8



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message