[
https://issues.apache.org/jira/browse/LANG-434?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12594434#action_12594434
]
prophecy edited comment on LANG-434 at 5/5/08 6:26 PM:
------------------------------------------------------------
Not a patch, but this should work as the equivalent of the Math.ceil().
{code}
public Date ciel(Date d, int field) {
d = DateUtils.add(d, field, +1);
d = DateUtils.truncate(d, field);
return d;
}
{code}
Quick visual test:
Date d;
d = new Date();
System.out.println("now=" + d);
System.out.println("ciel=" + ciel(d, Calendar.YEAR));
System.out.println("ciel=" + ciel(d, Calendar.MONTH));
System.out.println("ciel=" + ciel(d, Calendar.DAY_OF_MONTH));
System.out.println("ciel=" + ciel(d, Calendar.HOUR));
System.out.println("ciel=" + ciel(d, Calendar.MINUTE));
was (Author: prophecy):
Not a patch, but this should work as the equivalent of the Math.ceil().
public Date ciel(Date d, int field) {
d = DateUtils.add(d, field, +1);
d = DateUtils.truncate(d, field);
return d;
}
Quick visual test:
Date d;
d = new Date();
System.out.println("now=" + d);
System.out.println("ciel=" + ciel(d, Calendar.YEAR));
System.out.println("ciel=" + ciel(d, Calendar.MONTH));
System.out.println("ciel=" + ciel(d, Calendar.DAY_OF_MONTH));
System.out.println("ciel=" + ciel(d, Calendar.HOUR));
System.out.println("ciel=" + ciel(d, Calendar.MINUTE));
> 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.