Lukasz Lenart created WW-5738:
---------------------------------
Summary: <s:date/> should render a java.sql.Date at start of day,
not at the current wall-clock time
Key: WW-5738
URL: https://issues.apache.org/jira/browse/WW-5738
Project: Struts 2
Issue Type: Bug
Components: Core Tags
Reporter: Lukasz Lenart
Fix For: 8.0.0
Split out of WW-5686, which keeps only the test de-flaking at 7.4.0. This
ticket carries the rendering change, deferred to 8.0.0 because it alters
observable output.
h3. Current behaviour
{{org.apache.struts2.components.Date.end}} completes a {{java.sql.Date}} with
the current time-of-day:
{code:java}if (dateObject instanceof java.sql.Date) {
date = ((java.sql.Date)
dateObject).toLocalDate().atTime(LocalTime.now(tz)).atZone(tz);
}
{code}
A {{java.sql.Date}} carries no time-of-day, so any {{format}} with time fields
(including the default {{DateFormat.MEDIUM}} date-time instance) renders
whatever the wall clock says at render time. The same value rendered twice on
one page produces two different strings, and {{nice="true"}} reports "a moment
ago" for today's date regardless of when it was set.
h3. History
* WW-5197 (6.0.3) added {{java.sql.Date}} support as
{{toLocalDate().atStartOfDay(tz)}} - deterministic midnight.
* WW-5272 (commit {{08de24588}}, 6.2.0) fixed the
{{UnsupportedOperationException}} thrown by {{java.sql.Time.toInstant()}}. The
{{java.sql.Time}} branch it added needs _a_ date to complete a
{{ZonedDateTime}}, so it uses today's. In the same commit the {{java.sql.Date}}
branch was switched to {{atTime(LocalTime.now(tz))}}; the ticket never mentions
{{java.sql.Date}}, so this reads as collateral rather than an intended change,
and it shipped without a note.
h3. Proposed change
Restore {{toLocalDate().atStartOfDay(tz)}} for {{java.sql.Date}}. This matches
how the {{LocalDate}} branch a few lines below already completes a date-only
value, and makes the output reproducible.
Extend {{DateTest.testJavaSqlDate}} (which after WW-5686 renders only the date
fields) to also assert the time fields render as {{00:00:00}}.
h3. Why 8.0.0
Every application on 6.2.0 through 7.x that renders a {{java.sql.Date}} with a
time-bearing format will see the time part change from "now" to midnight. That
needs a Version Notes / Migration Guide entry and belongs in a major release.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)