commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (LANG-1255) need a version of DateUtils.toCalendar that preserves or sets TimeZone
Date Thu, 04 Aug 2016 17:11:20 GMT

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

Gary Gregory updated LANG-1255:
-------------------------------
    Description: 
DateUtils.toCalendar creates a Calendar using .getInstance(). This results in a Calendar in
the machine's timezone. The Date object passed in may not be in that same timezone. Since
the getTimezoneOffset method of Date is deprecated a new version of toCalendar that accepts
a TimeZone would be appropriate:

{code:java}
    public static Calendar toCalendar(final Date date, final TimeZone tz) {
        final Calendar c = Calendar.getInstance(tz);
        c.setTime(date);
        return c;
    }
{code}

  was:
DateUtils.toCalendar creates a Calendar using .getInstance(). This results in a Calendar in
the machine's timezone. The Date object passed in may not be in that same timezone. Since
the getTimezoneOffset method of Date is deprecated a new version of toCalendar that accepts
a TimeZone would be appropriate:

    public static Calendar toCalendar(final Date date, final TimeZone tz) {
        final Calendar c = Calendar.getInstance(tz);
        c.setTime(date);
        return c;
    }



> need a version of DateUtils.toCalendar that preserves or sets TimeZone
> ----------------------------------------------------------------------
>
>                 Key: LANG-1255
>                 URL: https://issues.apache.org/jira/browse/LANG-1255
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.time.*
>    Affects Versions: 3.4
>            Reporter: Mike Calmus
>
> DateUtils.toCalendar creates a Calendar using .getInstance(). This results in a Calendar
in the machine's timezone. The Date object passed in may not be in that same timezone. Since
the getTimezoneOffset method of Date is deprecated a new version of toCalendar that accepts
a TimeZone would be appropriate:
> {code:java}
>     public static Calendar toCalendar(final Date date, final TimeZone tz) {
>         final Calendar c = Calendar.getInstance(tz);
>         c.setTime(date);
>         return c;
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message