You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Sujan Biswas <ri...@gmail.com> on 2023/11/06 16:35:13 UTC
[lang] DurationFormatUtils does not calculate duration for some specific dates and times
Hi Team,
Please find the below test case and observation which seems to be a bug in
the DurationFormatUtils class. If you look at the calculated duration it
says "Duration : *00-11130235300000*" with output format as
yyyyMMddHHmmssSSS.
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<scope>provided</scope>
@Test
void getElapsedTimerTest() {
String DATE_TIME_FORMAT = "yyyyMMddHHmmssSSS";
long startEpochMillis = 1698541052000L; //Date and time (GMT): Sunday, 29
October 2023 00:57:32
long endEpochMillis = 1698544232000L; //Date and time (GMT): Sunday, 29
October 2023 01:50:32
String duration = DurationFormatUtils.formatPeriod(startEpochMillis,
endEpochMillis, DATE_TIME_FORMAT);
System.out.println("Start Time : " + Instant.ofEpochMilli(startEpochMillis))
;
System.out.println("End Time : " + Instant.ofEpochMilli(endEpochMillis));
System.out.println("Duration : " + duration);
}
Console Output:
Start Time : 2023-10-29T00:57:32Z End Time : 2023-10-29T01:50:32Z Duration
: *00-11130235300000*
Regards,
Sujan Biswas
Re: [lang] DurationFormatUtils does not calculate duration for some specific dates and times
Posted by Sujan Biswas <ri...@gmail.com>.
Please ignore the email. I need to pass the TimeZone for calculation,
otherwise it was taking the system default timezone which changes during
DayLight Saving.
Thanks,
Sujan
On Mon, 6 Nov 2023 at 16:35, Sujan Biswas <ri...@gmail.com> wrote:
> Hi Team,
>
> Please find the below test case and observation which seems to be a bug in
> the DurationFormatUtils class. If you look at the calculated duration it
> says "Duration : *00-11130235300000*" with output format as
> yyyyMMddHHmmssSSS.
>
> <groupId>org.apache.commons</groupId>
> <artifactId>commons-lang3</artifactId>
> <version>3.12.0</version>
> <scope>provided</scope>
>
> @Test
> void getElapsedTimerTest() {
>
> String DATE_TIME_FORMAT = "yyyyMMddHHmmssSSS";
> long startEpochMillis = 1698541052000L; //Date and time (GMT): Sunday, 29
> October 2023 00:57:32
> long endEpochMillis = 1698544232000L; //Date and time (GMT): Sunday, 29
> October 2023 01:50:32
>
> String duration = DurationFormatUtils.formatPeriod(startEpochMillis,
> endEpochMillis, DATE_TIME_FORMAT);
>
> System.out.println("Start Time : " + Instant.ofEpochMilli
> (startEpochMillis));
> System.out.println("End Time : " + Instant.ofEpochMilli(endEpochMillis));
> System.out.println("Duration : " + duration);
>
>
> }
>
> Console Output:
>
> Start Time : 2023-10-29T00:57:32Z End Time : 2023-10-29T01:50:32Z Duration
> : *00-11130235300000*
>
> Regards,
> Sujan Biswas
>