You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Rafael Sisto (JIRA)" <ji...@apache.org> on 2012/11/06 19:40:13 UTC

[jira] [Created] (LANG-850) DateUtils.truncatedCompareTo not working properly with DST timezones

Rafael Sisto created LANG-850:
---------------------------------

             Summary: 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


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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-850) DateUtils.truncatedCompareTo not working properly with DST timezones

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-850?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13491885#comment-13491885 ] 

Sebb commented on LANG-850:
---------------------------

I'm not sure what the issue is here: the two calendars objects are not the same, because they have different TimeZones.

This seems to be more about how calendar objects behave when their timezone is changed.
                
> 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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-850) DateUtils.truncatedCompareTo not working properly with DST timezones

Posted by "Rafael Sisto (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-850?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13492091#comment-13492091 ] 

Rafael Sisto commented on LANG-850:
-----------------------------------

Thanks for clearing that, so the method truncates taking account of the current timezone of the calendar.

I was having problems when comparing:
1-an XMLGregorianCalendar converted to Calendar (XMLGregorianCalendar doesn't have the concept of DST, so the timezone is converted to GMT-2 in this timezone) with
2-a GregorianCalendar created with "new GregorianCalendar()" which has a timezone of "America/Montevideo".

According to the comments, my code should set the timezone of the converted XMLGregorianCalendar to America/Montevideo before using the truncate method.

Thanks again, I had thought that the truncatedCompareTo should compare dates managing the timezone before comparing.
                
> 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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-850) DateUtils.truncatedCompareTo not working properly with DST timezones

Posted by "Rafael Sisto (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-850?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13492034#comment-13492034 ] 

Rafael Sisto commented on LANG-850:
-----------------------------------

I agree with that (the objects aren't the same), but shouldn't the months of both calendars match? Which is the same as saying that the last line should return 0, right?

As a clear example, the month of 11-6-2012 (GMT-3) is the same as the month of 11-20-2012 (GMT-7), right? 
What am I thinking wrong here?
                
> 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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-850) DateUtils.truncatedCompareTo not working properly with DST timezones

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-850?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13492068#comment-13492068 ] 

Sebb commented on LANG-850:
---------------------------

AFAICT, the problem arises in your test because the calendar objects are created with the default timezone and the timezone is then changed.

If you change the default timezone before creating the calendar objects, then they truncate as expected.
However they still won't be equal because of the time zone difference.

I'm also not clear what the use case is here.
                
> 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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira