commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Closed: (LANG-414) DateUtils.round() often fails
Date Sun, 24 Feb 2008 04:25:19 GMT

     [ https://issues.apache.org/jira/browse/LANG-414?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Yandell closed LANG-414.
------------------------------

    Resolution: Duplicate

Thanks Peter - this was reported earlier (LANG-346) and you should find that the latest code
in SVN [and the forthcoming 2.4] fix it.

> DateUtils.round() often fails
> -----------------------------
>
>                 Key: LANG-414
>                 URL: https://issues.apache.org/jira/browse/LANG-414
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.2, 2.3
>            Reporter: Peter Schreuer
>            Priority: Critical
>             Fix For: 2.4
>
>
> The example below shows the failure of DateUtils.round(Date,int). With version 2.1 round()
works fine.
> {code}
>         Now                                 DateUtils                        calculated
directly     
> 2008-02-22T11:09:06,680 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:07,000
   ERROR
> 2008-02-22T11:09:06,680 Truncated: 2008-02-22T11:09:06,000         2008-02-22T11:09:06,000
   ok
> 2008-02-22T11:09:07,040 Rounded:   2008-02-22T11:09:07,000         2008-02-22T11:09:07,000
   ok
> 2008-02-22T11:09:07,040 Truncated: 2008-02-22T11:09:07,000         2008-02-22T11:09:07,000
   ok
> 2008-02-22T11:09:07,399 Rounded:   2008-02-22T11:09:07,000         2008-02-22T11:09:07,000
   ok
> 2008-02-22T11:09:07,399 Truncated: 2008-02-22T11:09:07,000         2008-02-22T11:09:07,000
   ok
> 2008-02-22T11:09:07,743 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:08,000
   ERROR
> 2008-02-22T11:09:07,743 Truncated: 2008-02-22T11:09:07,000         2008-02-22T11:09:07,000
   ok
> 2008-02-22T11:09:08,102 Rounded:   2008-02-22T11:09:08,000         2008-02-22T11:09:08,000
   ok
> 2008-02-22T11:09:08,102 Truncated: 2008-02-22T11:09:08,000         2008-02-22T11:09:08,000
   ok
> 2008-02-22T11:09:08,446 Rounded:   2008-02-22T11:09:08,000         2008-02-22T11:09:08,000
   ok
> 2008-02-22T11:09:08,446 Truncated: 2008-02-22T11:09:08,000         2008-02-22T11:09:08,000
   ok
> 2008-02-22T11:09:08,805 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:09,000
   ERROR
> 2008-02-22T11:09:08,805 Truncated: 2008-02-22T11:09:08,000         2008-02-22T11:09:08,000
   ok
> 2008-02-22T11:09:09,149 Rounded:   2008-02-22T11:09:09,000         2008-02-22T11:09:09,000
   ok
> 2008-02-22T11:09:09,149 Truncated: 2008-02-22T11:09:09,000         2008-02-22T11:09:09,000
   ok
> 2008-02-22T11:09:09,508 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:10,000
   ERROR
> 2008-02-22T11:09:09,508 Truncated: 2008-02-22T11:09:09,000         2008-02-22T11:09:09,000
   ok
> 2008-02-22T11:09:09,852 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:10,000
   ERROR
> 2008-02-22T11:09:09,852 Truncated: 2008-02-22T11:09:09,000         2008-02-22T11:09:09,000
   ok
> 2008-02-22T11:09:10,211 Rounded:   2008-02-22T11:09:10,000         2008-02-22T11:09:10,000
   ok
> 2008-02-22T11:09:10,211 Truncated: 2008-02-22T11:09:10,000         2008-02-22T11:09:10,000
   ok
> 2008-02-22T11:09:10,555 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:11,000
   ERROR
> 2008-02-22T11:09:10,555 Truncated: 2008-02-22T11:09:10,000         2008-02-22T11:09:10,000
   ok
> 2008-02-22T11:09:10,915 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:11,000
   ERROR
> 2008-02-22T11:09:10,915 Truncated: 2008-02-22T11:09:10,000         2008-02-22T11:09:10,000
   ok
> 2008-02-22T11:09:11,258 Rounded:   2008-02-22T11:09:11,000         2008-02-22T11:09:11,000
   ok
> 2008-02-22T11:09:11,258 Truncated: 2008-02-22T11:09:11,000         2008-02-22T11:09:11,000
   ok
> 2008-02-22T11:09:11,618 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:12,000
   ERROR
> 2008-02-22T11:09:11,618 Truncated: 2008-02-22T11:09:11,000         2008-02-22T11:09:11,000
   ok
> 2008-02-22T11:09:11,961 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:12,000
   ERROR
> 2008-02-22T11:09:11,961 Truncated: 2008-02-22T11:09:11,000         2008-02-22T11:09:11,000
   ok
> 2008-02-22T11:09:12,321 Rounded:   2008-02-22T11:09:12,000         2008-02-22T11:09:12,000
   ok
> 2008-02-22T11:09:12,321 Truncated: 2008-02-22T11:09:12,000         2008-02-22T11:09:12,000
   ok
> 2008-02-22T11:09:12,665 Rounded:   2008-02-22T11:00:01,000         2008-02-22T11:09:13,000
   ERROR
> 2008-02-22T11:09:12,665 Truncated: 2008-02-22T11:09:12,000         2008-02-22T11:09:12,000
   ok
> {code}
> {code:title=Example Code|borderStyle=solid}
> java.text.SimpleDateFormat dtFormat = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss,SSS");
> System.out.println(
>     "        Now            "
>     + "            "
>     + "   DateUtils  "
>     + "         "
>     + "       calculated directly "
>     + "    ");
> int errorCnt = 0;
> while(errorCnt < 10)
> {
>   java.util.Date now = new java.util.Date();
>   
>   java.util.Date roundedByUtils = org.apache.commons.lang.time.DateUtils.round(now, java.util.Calendar.SECOND);
>   java.util.Date truncatedByUtils = org.apache.commons.lang.time.DateUtils.truncate(now,
java.util.Calendar.SECOND);
>   
>   long rest = now.getTime() % 1000;
>   java.util.Date rounded;
>   java.util.Date truncated = new java.util.Date(now.getTime() - rest);
>   if (rest < 500)
>     rounded = truncated;
>   else
>     rounded = new java.util.Date(now.getTime() + (1000 - rest));
>   boolean roundError = !roundedByUtils.equals(rounded);
>   boolean truncateError = !truncatedByUtils.equals(truncated);
>   if (roundError || truncateError)
>     errorCnt++;
>   System.out.println(
>       dtFormat.format(now)
>       + " Rounded:   "
>       + dtFormat.format(roundedByUtils)
>       + "         "
>       + dtFormat.format(rounded)
>       + "    "
>       + (roundError ? "ERROR" : "ok"));
>   System.out.println(
>       dtFormat.format(now)
>       + " Truncated: "
>       + dtFormat.format(truncatedByUtils)
>       + "         "
>       + dtFormat.format(truncated)
>       + "    "
>       + (truncateError ? "ERROR" : "ok"));
>   Thread.sleep(351);
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message