You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Benedikt Ritter <br...@apache.org> on 2014/03/15 11:25:36 UTC
Re: svn commit: r1577332 - in /commons/proper/lang/trunk/src:
changes/changes.xml main/java/org/apache/commons/lang3/time/DateUtils.java test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
I guess this one was introduced by me when I tried to fix LANG-951 :-)
2014-03-13 22:40 GMT+01:00 <dj...@apache.org>:
> Author: djones
> Date: Thu Mar 13 21:40:26 2014
> New Revision: 1577332
>
> URL: http://svn.apache.org/r1577332
> Log:
> LANG-987: DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns wrong
> days, reported by Jay Xu.
>
> Modified:
> commons/proper/lang/trunk/src/changes/changes.xml
>
> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
>
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
>
> Modified: commons/proper/lang/trunk/src/changes/changes.xml
> URL:
> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1577332&r1=1577331&r2=1577332&view=diff
>
> ==============================================================================
> --- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
> +++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Thu Mar 13
> 21:40:26 2014
> @@ -22,6 +22,7 @@
> <body>
>
> <release version="3.4" date="TBA" description="TBA">
> + <action issue="LANG-987" type="fix"
> dev="djones">DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns
> wrong days</action>
> <action issue="LANG-983" type="fix" dev="sebb">DurationFormatUtils
> does not describe format string fully</action>
> <action issue="LANG-981" type="fix"
> dev="sebb">DurationFormatUtils#lexx does not detect unmatched quote
> char</action>
> <action issue="LANG-984" type="fix" dev="sebb">DurationFormatUtils
> does not handle large durations correctly</action>
>
> Modified:
> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java?rev=1577332&r1=1577331&r2=1577332&view=diff
>
> ==============================================================================
> ---
> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> (original)
> +++
> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> Thu Mar 13 21:40:26 2014
> @@ -1690,13 +1690,15 @@ public class DateUtils {
> final long millisPerUnit = getMillisPerUnit(unit);
> long result = 0;
>
> + int offset = (unit == Calendar.DAY_OF_YEAR) ? 0 : 1;
> +
> // Fragments bigger than a day require a breakdown to days
> switch (fragment) {
> case Calendar.YEAR:
> - result += ((calendar.get(Calendar.DAY_OF_YEAR) -1) *
> MILLIS_PER_DAY) / millisPerUnit;
> + result += ((calendar.get(Calendar.DAY_OF_YEAR) - offset)
> * MILLIS_PER_DAY) / millisPerUnit;
> break;
> case Calendar.MONTH:
> - result += ((calendar.get(Calendar.DAY_OF_MONTH) -1) *
> MILLIS_PER_DAY) / millisPerUnit;
> + result += ((calendar.get(Calendar.DAY_OF_MONTH) - offset)
> * MILLIS_PER_DAY) / millisPerUnit;
> break;
> default:
> break;
>
> Modified:
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java?rev=1577332&r1=1577331&r2=1577332&view=diff
>
> ==============================================================================
> ---
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> (original)
> +++
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> Thu Mar 13 21:40:26 2014
> @@ -561,4 +561,32 @@ testResult);
> / DateUtils.MILLIS_PER_HOUR,
> testResult);
> }
> +
> + @Test
> + public void testDaysOfMonthWithCalendar() throws Exception {
> + final long testResult = DateUtils.getFragmentInDays(aCalendar,
> Calendar.MONTH);
> + assertEquals(days, testResult);
> + }
> +
> + @Test
> + public void testDaysOfMonthWithDate() throws Exception {
> + final long testResult = DateUtils.getFragmentInDays(aDate,
> Calendar.MONTH);
> + final Calendar cal = Calendar.getInstance();
> + cal.setTime(aDate);
> + assertEquals(cal.get(Calendar.DAY_OF_MONTH), testResult);
> + }
> +
> + @Test
> + public void testDaysOfYearWithCalendar() throws Exception {
> + final long testResult = DateUtils.getFragmentInDays(aCalendar,
> Calendar.YEAR);
> + assertEquals(aCalendar.get(Calendar.DAY_OF_YEAR), testResult);
> + }
> +
> + @Test
> + public void testDaysOfYearWithDate() throws Exception {
> + final long testResult = DateUtils.getFragmentInDays(aDate,
> Calendar.YEAR);
> + final Calendar cal = Calendar.getInstance();
> + cal.setTime(aDate);
> + assertEquals(cal.get(Calendar.DAY_OF_YEAR), testResult);
> + }
> }
>
>
>
--
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter
Re: svn commit: r1577332 - in /commons/proper/lang/trunk/src:
changes/changes.xml main/java/org/apache/commons/lang3/time/DateUtils.java test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
Posted by Benedikt Ritter <br...@apache.org>.
2014-03-15 12:55 GMT+01:00 Duncan Jones <du...@wortharead.com>:
> On 15 Mar 2014 10:27, "Benedikt Ritter" <br...@apache.org> wrote:
> >
> > 2014-03-15 11:25 GMT+01:00 Benedikt Ritter <br...@apache.org>:
> >
> > > I guess this one was introduced by me when I tried to fix LANG-951 :-)
> > >
> >
> > The reporter doesn't seem to be amused... Does this call for a quit bug
> fix
> > release? I could prepare a RC today.
>
> Might be a good idea. There's not really a work-around available.
>
okay, I'll start preparing the RC now.
>
> Duncan
>
> >
> >
> > >
> > >
> > > 2014-03-13 22:40 GMT+01:00 <dj...@apache.org>:
> > >
> > > Author: djones
> > >> Date: Thu Mar 13 21:40:26 2014
> > >> New Revision: 1577332
> > >>
> > >> URL: http://svn.apache.org/r1577332
> > >> Log:
> > >> LANG-987: DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns
> wrong
> > >> days, reported by Jay Xu.
> > >>
> > >> Modified:
> > >> commons/proper/lang/trunk/src/changes/changes.xml
> > >>
> > >>
>
> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> > >>
> > >>
>
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> > >>
> > >> Modified: commons/proper/lang/trunk/src/changes/changes.xml
> > >> URL:
> > >>
>
> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1577332&r1=1577331&r2=1577332&view=diff
> > >>
> > >>
>
> ==============================================================================
> > >> --- commons/proper/lang/trunk/src/changes/changes.xml [utf-8]
> (original)
> > >> +++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Thu Mar
> 13
> > >> 21:40:26 2014
> > >> @@ -22,6 +22,7 @@
> > >> <body>
> > >>
> > >> <release version="3.4" date="TBA" description="TBA">
> > >> + <action issue="LANG-987" type="fix"
> > >> dev="djones">DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns
> > >> wrong days</action>
> > >> <action issue="LANG-983" type="fix"
> dev="sebb">DurationFormatUtils
> > >> does not describe format string fully</action>
> > >> <action issue="LANG-981" type="fix"
> > >> dev="sebb">DurationFormatUtils#lexx does not detect unmatched quote
> > >> char</action>
> > >> <action issue="LANG-984" type="fix"
> dev="sebb">DurationFormatUtils
> > >> does not handle large durations correctly</action>
> > >>
> > >> Modified:
> > >>
>
> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> > >> URL:
> > >>
>
> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java?rev=1577332&r1=1577331&r2=1577332&view=diff
> > >>
> > >>
>
> ==============================================================================
> > >> ---
> > >>
>
> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> > >> (original)
> > >> +++
> > >>
>
> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> > >> Thu Mar 13 21:40:26 2014
> > >> @@ -1690,13 +1690,15 @@ public class DateUtils {
> > >> final long millisPerUnit = getMillisPerUnit(unit);
> > >> long result = 0;
> > >>
> > >> + int offset = (unit == Calendar.DAY_OF_YEAR) ? 0 : 1;
> > >> +
> > >> // Fragments bigger than a day require a breakdown to days
> > >> switch (fragment) {
> > >> case Calendar.YEAR:
> > >> - result += ((calendar.get(Calendar.DAY_OF_YEAR) -1) *
> > >> MILLIS_PER_DAY) / millisPerUnit;
> > >> + result += ((calendar.get(Calendar.DAY_OF_YEAR) -
> offset)
> > >> * MILLIS_PER_DAY) / millisPerUnit;
> > >> break;
> > >> case Calendar.MONTH:
> > >> - result += ((calendar.get(Calendar.DAY_OF_MONTH) -1) *
> > >> MILLIS_PER_DAY) / millisPerUnit;
> > >> + result += ((calendar.get(Calendar.DAY_OF_MONTH) -
> > >> offset) * MILLIS_PER_DAY) / millisPerUnit;
> > >> break;
> > >> default:
> > >> break;
> > >>
> > >> Modified:
> > >>
>
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> > >> URL:
> > >>
>
> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java?rev=1577332&r1=1577331&r2=1577332&view=diff
> > >>
> > >>
>
> ==============================================================================
> > >> ---
> > >>
>
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> > >> (original)
> > >> +++
> > >>
>
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> > >> Thu Mar 13 21:40:26 2014
> > >> @@ -561,4 +561,32 @@ testResult);
> > >> / DateUtils.MILLIS_PER_HOUR,
> > >> testResult);
> > >> }
> > >> +
> > >> + @Test
> > >> + public void testDaysOfMonthWithCalendar() throws Exception {
> > >> + final long testResult =
> DateUtils.getFragmentInDays(aCalendar,
> > >> Calendar.MONTH);
> > >> + assertEquals(days, testResult);
> > >> + }
> > >> +
> > >> + @Test
> > >> + public void testDaysOfMonthWithDate() throws Exception {
> > >> + final long testResult = DateUtils.getFragmentInDays(aDate,
> > >> Calendar.MONTH);
> > >> + final Calendar cal = Calendar.getInstance();
> > >> + cal.setTime(aDate);
> > >> + assertEquals(cal.get(Calendar.DAY_OF_MONTH), testResult);
> > >> + }
> > >> +
> > >> + @Test
> > >> + public void testDaysOfYearWithCalendar() throws Exception {
> > >> + final long testResult =
> DateUtils.getFragmentInDays(aCalendar,
> > >> Calendar.YEAR);
> > >> + assertEquals(aCalendar.get(Calendar.DAY_OF_YEAR),
> testResult);
> > >> + }
> > >> +
> > >> + @Test
> > >> + public void testDaysOfYearWithDate() throws Exception {
> > >> + final long testResult = DateUtils.getFragmentInDays(aDate,
> > >> Calendar.YEAR);
> > >> + final Calendar cal = Calendar.getInstance();
> > >> + cal.setTime(aDate);
> > >> + assertEquals(cal.get(Calendar.DAY_OF_YEAR), testResult);
> > >> + }
> > >> }
> > >>
> > >>
> > >>
> > >
> > >
> > > --
> > > http://people.apache.org/~britter/
> > > http://www.systemoutprintln.de/
> > > http://twitter.com/BenediktRitter
> > > http://github.com/britter
> > >
> >
> >
> >
> > --
> > http://people.apache.org/~britter/
> > http://www.systemoutprintln.de/
> > http://twitter.com/BenediktRitter
> > http://github.com/britter
>
--
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter
Re: svn commit: r1577332 - in /commons/proper/lang/trunk/src:
changes/changes.xml main/java/org/apache/commons/lang3/time/DateUtils.java test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
Posted by Duncan Jones <du...@wortharead.com>.
On 15 Mar 2014 10:27, "Benedikt Ritter" <br...@apache.org> wrote:
>
> 2014-03-15 11:25 GMT+01:00 Benedikt Ritter <br...@apache.org>:
>
> > I guess this one was introduced by me when I tried to fix LANG-951 :-)
> >
>
> The reporter doesn't seem to be amused... Does this call for a quit bug
fix
> release? I could prepare a RC today.
Might be a good idea. There's not really a work-around available.
Duncan
>
>
> >
> >
> > 2014-03-13 22:40 GMT+01:00 <dj...@apache.org>:
> >
> > Author: djones
> >> Date: Thu Mar 13 21:40:26 2014
> >> New Revision: 1577332
> >>
> >> URL: http://svn.apache.org/r1577332
> >> Log:
> >> LANG-987: DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns
wrong
> >> days, reported by Jay Xu.
> >>
> >> Modified:
> >> commons/proper/lang/trunk/src/changes/changes.xml
> >>
> >>
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> >>
> >>
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> >>
> >> Modified: commons/proper/lang/trunk/src/changes/changes.xml
> >> URL:
> >>
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1577332&r1=1577331&r2=1577332&view=diff
> >>
> >>
==============================================================================
> >> --- commons/proper/lang/trunk/src/changes/changes.xml [utf-8]
(original)
> >> +++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Thu Mar
13
> >> 21:40:26 2014
> >> @@ -22,6 +22,7 @@
> >> <body>
> >>
> >> <release version="3.4" date="TBA" description="TBA">
> >> + <action issue="LANG-987" type="fix"
> >> dev="djones">DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns
> >> wrong days</action>
> >> <action issue="LANG-983" type="fix" dev="sebb">DurationFormatUtils
> >> does not describe format string fully</action>
> >> <action issue="LANG-981" type="fix"
> >> dev="sebb">DurationFormatUtils#lexx does not detect unmatched quote
> >> char</action>
> >> <action issue="LANG-984" type="fix" dev="sebb">DurationFormatUtils
> >> does not handle large durations correctly</action>
> >>
> >> Modified:
> >>
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> >> URL:
> >>
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java?rev=1577332&r1=1577331&r2=1577332&view=diff
> >>
> >>
==============================================================================
> >> ---
> >>
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> >> (original)
> >> +++
> >>
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
> >> Thu Mar 13 21:40:26 2014
> >> @@ -1690,13 +1690,15 @@ public class DateUtils {
> >> final long millisPerUnit = getMillisPerUnit(unit);
> >> long result = 0;
> >>
> >> + int offset = (unit == Calendar.DAY_OF_YEAR) ? 0 : 1;
> >> +
> >> // Fragments bigger than a day require a breakdown to days
> >> switch (fragment) {
> >> case Calendar.YEAR:
> >> - result += ((calendar.get(Calendar.DAY_OF_YEAR) -1) *
> >> MILLIS_PER_DAY) / millisPerUnit;
> >> + result += ((calendar.get(Calendar.DAY_OF_YEAR) -
offset)
> >> * MILLIS_PER_DAY) / millisPerUnit;
> >> break;
> >> case Calendar.MONTH:
> >> - result += ((calendar.get(Calendar.DAY_OF_MONTH) -1) *
> >> MILLIS_PER_DAY) / millisPerUnit;
> >> + result += ((calendar.get(Calendar.DAY_OF_MONTH) -
> >> offset) * MILLIS_PER_DAY) / millisPerUnit;
> >> break;
> >> default:
> >> break;
> >>
> >> Modified:
> >>
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> >> URL:
> >>
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java?rev=1577332&r1=1577331&r2=1577332&view=diff
> >>
> >>
==============================================================================
> >> ---
> >>
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> >> (original)
> >> +++
> >>
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
> >> Thu Mar 13 21:40:26 2014
> >> @@ -561,4 +561,32 @@ testResult);
> >> / DateUtils.MILLIS_PER_HOUR,
> >> testResult);
> >> }
> >> +
> >> + @Test
> >> + public void testDaysOfMonthWithCalendar() throws Exception {
> >> + final long testResult = DateUtils.getFragmentInDays(aCalendar,
> >> Calendar.MONTH);
> >> + assertEquals(days, testResult);
> >> + }
> >> +
> >> + @Test
> >> + public void testDaysOfMonthWithDate() throws Exception {
> >> + final long testResult = DateUtils.getFragmentInDays(aDate,
> >> Calendar.MONTH);
> >> + final Calendar cal = Calendar.getInstance();
> >> + cal.setTime(aDate);
> >> + assertEquals(cal.get(Calendar.DAY_OF_MONTH), testResult);
> >> + }
> >> +
> >> + @Test
> >> + public void testDaysOfYearWithCalendar() throws Exception {
> >> + final long testResult = DateUtils.getFragmentInDays(aCalendar,
> >> Calendar.YEAR);
> >> + assertEquals(aCalendar.get(Calendar.DAY_OF_YEAR), testResult);
> >> + }
> >> +
> >> + @Test
> >> + public void testDaysOfYearWithDate() throws Exception {
> >> + final long testResult = DateUtils.getFragmentInDays(aDate,
> >> Calendar.YEAR);
> >> + final Calendar cal = Calendar.getInstance();
> >> + cal.setTime(aDate);
> >> + assertEquals(cal.get(Calendar.DAY_OF_YEAR), testResult);
> >> + }
> >> }
> >>
> >>
> >>
> >
> >
> > --
> > http://people.apache.org/~britter/
> > http://www.systemoutprintln.de/
> > http://twitter.com/BenediktRitter
> > http://github.com/britter
> >
>
>
>
> --
> http://people.apache.org/~britter/
> http://www.systemoutprintln.de/
> http://twitter.com/BenediktRitter
> http://github.com/britter
Re: svn commit: r1577332 - in /commons/proper/lang/trunk/src:
changes/changes.xml main/java/org/apache/commons/lang3/time/DateUtils.java test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
Posted by Benedikt Ritter <br...@apache.org>.
2014-03-15 11:25 GMT+01:00 Benedikt Ritter <br...@apache.org>:
> I guess this one was introduced by me when I tried to fix LANG-951 :-)
>
The reporter doesn't seem to be amused... Does this call for a quit bug fix
release? I could prepare a RC today.
>
>
> 2014-03-13 22:40 GMT+01:00 <dj...@apache.org>:
>
> Author: djones
>> Date: Thu Mar 13 21:40:26 2014
>> New Revision: 1577332
>>
>> URL: http://svn.apache.org/r1577332
>> Log:
>> LANG-987: DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns wrong
>> days, reported by Jay Xu.
>>
>> Modified:
>> commons/proper/lang/trunk/src/changes/changes.xml
>>
>> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
>>
>> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
>>
>> Modified: commons/proper/lang/trunk/src/changes/changes.xml
>> URL:
>> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1577332&r1=1577331&r2=1577332&view=diff
>>
>> ==============================================================================
>> --- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
>> +++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Thu Mar 13
>> 21:40:26 2014
>> @@ -22,6 +22,7 @@
>> <body>
>>
>> <release version="3.4" date="TBA" description="TBA">
>> + <action issue="LANG-987" type="fix"
>> dev="djones">DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns
>> wrong days</action>
>> <action issue="LANG-983" type="fix" dev="sebb">DurationFormatUtils
>> does not describe format string fully</action>
>> <action issue="LANG-981" type="fix"
>> dev="sebb">DurationFormatUtils#lexx does not detect unmatched quote
>> char</action>
>> <action issue="LANG-984" type="fix" dev="sebb">DurationFormatUtils
>> does not handle large durations correctly</action>
>>
>> Modified:
>> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
>> URL:
>> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java?rev=1577332&r1=1577331&r2=1577332&view=diff
>>
>> ==============================================================================
>> ---
>> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
>> (original)
>> +++
>> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DateUtils.java
>> Thu Mar 13 21:40:26 2014
>> @@ -1690,13 +1690,15 @@ public class DateUtils {
>> final long millisPerUnit = getMillisPerUnit(unit);
>> long result = 0;
>>
>> + int offset = (unit == Calendar.DAY_OF_YEAR) ? 0 : 1;
>> +
>> // Fragments bigger than a day require a breakdown to days
>> switch (fragment) {
>> case Calendar.YEAR:
>> - result += ((calendar.get(Calendar.DAY_OF_YEAR) -1) *
>> MILLIS_PER_DAY) / millisPerUnit;
>> + result += ((calendar.get(Calendar.DAY_OF_YEAR) - offset)
>> * MILLIS_PER_DAY) / millisPerUnit;
>> break;
>> case Calendar.MONTH:
>> - result += ((calendar.get(Calendar.DAY_OF_MONTH) -1) *
>> MILLIS_PER_DAY) / millisPerUnit;
>> + result += ((calendar.get(Calendar.DAY_OF_MONTH) -
>> offset) * MILLIS_PER_DAY) / millisPerUnit;
>> break;
>> default:
>> break;
>>
>> Modified:
>> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
>> URL:
>> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java?rev=1577332&r1=1577331&r2=1577332&view=diff
>>
>> ==============================================================================
>> ---
>> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
>> (original)
>> +++
>> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
>> Thu Mar 13 21:40:26 2014
>> @@ -561,4 +561,32 @@ testResult);
>> / DateUtils.MILLIS_PER_HOUR,
>> testResult);
>> }
>> +
>> + @Test
>> + public void testDaysOfMonthWithCalendar() throws Exception {
>> + final long testResult = DateUtils.getFragmentInDays(aCalendar,
>> Calendar.MONTH);
>> + assertEquals(days, testResult);
>> + }
>> +
>> + @Test
>> + public void testDaysOfMonthWithDate() throws Exception {
>> + final long testResult = DateUtils.getFragmentInDays(aDate,
>> Calendar.MONTH);
>> + final Calendar cal = Calendar.getInstance();
>> + cal.setTime(aDate);
>> + assertEquals(cal.get(Calendar.DAY_OF_MONTH), testResult);
>> + }
>> +
>> + @Test
>> + public void testDaysOfYearWithCalendar() throws Exception {
>> + final long testResult = DateUtils.getFragmentInDays(aCalendar,
>> Calendar.YEAR);
>> + assertEquals(aCalendar.get(Calendar.DAY_OF_YEAR), testResult);
>> + }
>> +
>> + @Test
>> + public void testDaysOfYearWithDate() throws Exception {
>> + final long testResult = DateUtils.getFragmentInDays(aDate,
>> Calendar.YEAR);
>> + final Calendar cal = Calendar.getInstance();
>> + cal.setTime(aDate);
>> + assertEquals(cal.get(Calendar.DAY_OF_YEAR), testResult);
>> + }
>> }
>>
>>
>>
>
>
> --
> http://people.apache.org/~britter/
> http://www.systemoutprintln.de/
> http://twitter.com/BenediktRitter
> http://github.com/britter
>
--
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter