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-850) DateUtils.truncatedCompareTo not working properly with DST timezones
Date Wed, 16 Oct 2013 08:51:42 GMT

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

Henri Yandell closed LANG-850.
------------------------------

    Resolution: Not A Problem

Looks like this conversation was resolved :)

> DateUtils.truncatedCompareTo not working properly with DST timezones
> --------------------------------------------------------------------
>
>                 Key: LANG-850
>                 URL: https://issues.apache.org/jira/browse/LANG-850
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.1
>         Environment: java version "1.6.0_32"
> Windows 7
> Timezone: America/Montevideo
>            Reporter: Rafael Sisto
>            Priority: Minor
>              Labels: patch
>
> The method truncatedCompareTo doesn't work properly when comparing 2 calendars in a different
timezone (when one of them is "America/Montevideo", the same as the machine running the test).
> Here is the sample code to reproduce.
> The Timezone of the computer has to be set to UTC-3 Montevideo, with DST.
> {quote}
> GregorianCalendar c1 = new GregorianCalendar(2012,10,6);
> System.out.println("The time: " + c1.getTime());
> c1.setTimeZone(TimeZone.getTimeZone("America/Montevideo"));
> Calendar truncate1 =  DateUtils.truncate(c1, Calendar.MONTH);
> System.out.println("America/Montevideo then truncated: " + truncate1.getTime());
> GregorianCalendar c2 = new GregorianCalendar(2012,10,6);
> c2.setTimeZone(TimeZone.getTimeZone("GMT"));
> Calendar truncate2 = DateUtils.truncate(c2, Calendar.MONTH);
> System.out.println("GMT then truncated: " + truncate2.getTime());
> 		
> System.out.println("Truncated compare: " + DateUtils.truncatedCompareTo(c1, c2, Calendar.MONTH));
> {quote}
> The output:
> {quote}
> The time: Tue Nov 06 00:00:00 UYST 2012
> America/Montevideo then truncated: Thu Nov 01 00:00:00 UYST 2012
> GMT then truncated: Wed Oct 31 22:00:00 UYST 2012
> Truncated compare: 1
> {quote}
> A suggestion is to change the TimeZone of both calendars before truncating. For example,
setting both to TimeZone.getDefault().



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message