[
https://issues.apache.org/jira/browse/LANG-434?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12600550#action_12600550
]
Robert Scholte commented on LANG-434:
-------------------------------------
I've started creating a patch and wrote some tests based on the truncate and
round-tests, but I ran into something strange. Watch the following sniplets:
{code:title=DateUtilsTest.java}
protected void setUp() throws Exception {
dateAmPm1 = dateTimeParser.parse("February 3, 2002 01:10:00.000");
dateAmPm2 = dateTimeParser.parse("February 3, 2002 11:10:00.000");
dateAmPm3 = dateTimeParser.parse("February 3, 2002 13:10:00.000");
dateAmPm4 = dateTimeParser.parse("February 3, 2002 19:10:00.000");
}
{code}
and
{code:title=DateUtilsTest.java}
public void testRound() throws Exception {
assertEquals("truncate ampm-1 failed",
dateTimeParser.parse("February 3, 2002 00:00:00.000"),
DateUtils.round(dateAmPm1, Calendar.AM_PM));
assertEquals("truncate ampm-2 failed",
dateTimeParser.parse("February 4, 2002 00:00:00.000"),
DateUtils.round(dateAmPm2, Calendar.AM_PM));
assertEquals("truncate ampm-3 failed",
dateTimeParser.parse("February 3, 2002 12:00:00.000"),
DateUtils.round(dateAmPm3, Calendar.AM_PM));
assertEquals("truncate ampm-4 failed",
dateTimeParser.parse("February 4, 2002 12:00:00.000"),
DateUtils.round(dateAmPm4, Calendar.AM_PM));
}
{code}
Minor issue: the comment has to be round instead of truncate
But I'd expected the values round to the nearest noon or midnight. In other
words:
ampm-2 as "February 3, 2002 12:00:00.000"
ampm-4 as "February 4, 2002 00:00:00.000"
Could someone explain to me what's going on?
> Add DateUtils.ceiling() method
> ------------------------------
>
> Key: LANG-434
> URL: https://issues.apache.org/jira/browse/LANG-434
> Project: Commons Lang
> Issue Type: Improvement
> Affects Versions: 2.4
> Reporter: Travis Reeder
> Fix For: 3.0
>
>
> It would be nice to have a DateUtils.ceiling methods which would be the
> opposite of truncate (which is equivalent to floor)
> DateUtils.ceiling(Date d, int field);
> For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you
> passed with HOUR, it would return 28 Mar 2002 13:59:59.999. If this was
> passed with MONTH, it would return 31 Mar 2002 23:59:59.999.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.