### Eclipse Workspace Patch 1.0 #P org.eclipse.mylyn.bugzilla.tests Index: src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java,v retrieving revision 1.43 diff -u -r1.43 AllBugzillaTests.java --- src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java 29 Jan 2009 16:16:34 -0000 1.43 +++ src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java 2 Jun 2009 04:02:23 -0000 @@ -43,6 +43,7 @@ suite.addTestSuite(BugzillaTaskHistoryTest.class); suite.addTestSuite(BugzillaRepository32Test.class); suite.addTestSuite(BugzillaVersionTest.class); + suite.addTestSuite(BugzillaDateTimeTests.class); return suite; } Index: src/org/eclipse/mylyn/bugzilla/tests/BugzillaDateTimeTests.java =================================================================== RCS file: src/org/eclipse/mylyn/bugzilla/tests/BugzillaDateTimeTests.java diff -N src/org/eclipse/mylyn/bugzilla/tests/BugzillaDateTimeTests.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/mylyn/bugzilla/tests/BugzillaDateTimeTests.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.bugzilla.tests; + +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + +import junit.framework.TestCase; + +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttributeMapper; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector; +import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.core.data.TaskData; + +public class BugzillaDateTimeTests extends TestCase { + + private TaskRepository repository; + + private BugzillaRepositoryConnector connector; + + @Override + protected void setUp() throws Exception { + super.setUp(); + this.connector = (BugzillaRepositoryConnector) TasksUiPlugin.getRepositoryManager().getRepositoryConnector( + BugzillaCorePlugin.CONNECTOR_KIND); + this.repository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND, + IBugzillaTestConstants.TEST_BUGZILLA_323_URL); + } + + public void testTimezones() throws Exception { + TimeZone defaultTimeZone = TimeZone.getDefault(); + try { + TimeZone.setDefault(TimeZone.getTimeZone("America/Vancouver")); + BugzillaAttributeMapper mapper = (BugzillaAttributeMapper) connector.getTaskDataHandler() + .getAttributeMapper(repository); + TaskData taskData = new TaskData(mapper, BugzillaCorePlugin.CONNECTOR_KIND, + IBugzillaTestConstants.TEST_BUGZILLA_323_URL, "1"); + TaskAttribute attribute = taskData.getRoot().createAttribute(BugzillaAttribute.DELTA_TS.getKey()); + attribute.setValue("2009-05-21 12:03:06 PST"); + Date a = mapper.getDateValue(attribute); + Calendar b = Calendar.getInstance(); + b.setTime(a); + assertEquals(2009, b.get(Calendar.YEAR)); + assertEquals(4, b.get(Calendar.MONTH)); + assertEquals(21, b.get(Calendar.DAY_OF_MONTH)); + assertEquals(13, b.get(Calendar.HOUR_OF_DAY)); + assertEquals(3, b.get(Calendar.MINUTE)); + assertEquals(6, b.get(Calendar.SECOND)); + assertEquals(1242936186000L, a.getTime()); + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + a = mapper.getDateValue(attribute); + b = Calendar.getInstance(); + b.setTime(a); + assertEquals(2009, b.get(Calendar.YEAR)); + assertEquals(4, b.get(Calendar.MONTH)); + assertEquals(21, b.get(Calendar.DAY_OF_MONTH)); + assertEquals(20, b.get(Calendar.HOUR_OF_DAY)); + assertEquals(3, b.get(Calendar.MINUTE)); + assertEquals(6, b.get(Calendar.SECOND)); + assertEquals(1242936186000L, a.getTime()); + } finally { + TimeZone.setDefault(defaultTimeZone); + } + } +} #P org.eclipse.mylyn.bugzilla.core Index: src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java,v retrieving revision 1.20 diff -u -r1.20 BugzillaAttributeMapper.java --- src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java 18 May 2009 06:31:36 -0000 1.20 +++ src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java 2 Jun 2009 04:02:24 -0000 @@ -29,30 +29,49 @@ */ public class BugzillaAttributeMapper extends TaskAttributeMapper { - private static final String DATE_FORMAT_1 = "yyyy-MM-dd HH:mm"; //$NON-NLS-1$ + private final SimpleDateFormat delta_ts_Format; - private static final String DATE_FORMAT_2 = "yyyy-MM-dd HH:mm:ss"; //$NON-NLS-1$ + private final SimpleDateFormat delta_ts_Format_Timezone; - private static final String DATE_FORMAT_3 = "yyyy-MM-dd"; //$NON-NLS-1$ + private final SimpleDateFormat creation_ts_Format; - private static final String delta_ts_format = DATE_FORMAT_2; + private final SimpleDateFormat creation_ts_Format_Timezone; - private static final String creation_ts_format = DATE_FORMAT_1; + private final SimpleDateFormat deadline_Format; - private static final String deadline_format = DATE_FORMAT_3; + private final SimpleDateFormat deadline_Format_Timezone; - private static final String customAttribute_format = DATE_FORMAT_2; + private final SimpleDateFormat customAttribute_Format; + + private final SimpleDateFormat customAttribute_Format_Timezone; /** - * public for testing Bugzilla 2.18 uses DATE_FORMAT_1 but later versions use DATE_FORMAT_2 Using lowest common - * denominator DATE_FORMAT_1 + * public for testing Bugzilla 2.18 uses "yyyy-MM-dd HH:mm" but later versions use "yyyy-MM-dd HH:mm:ss" Using + * lowest common denominator "yyyy-MM-dd HH:mm" */ - public static final String comment_creation_ts_format = DATE_FORMAT_1; + private final SimpleDateFormat comment_creation_ts_Format; + + private final SimpleDateFormat comment_creation_ts_Format_Timezone; + + private final SimpleDateFormat attachment_creation_ts_Format; - private static final String attachment_creation_ts_format = DATE_FORMAT_1; + private final SimpleDateFormat attachment_creation_ts_Format_Timezone; public BugzillaAttributeMapper(TaskRepository taskRepository) { super(taskRepository); + delta_ts_Format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //$NON-NLS-1$ + creation_ts_Format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //$NON-NLS-1$ + deadline_Format = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$ + customAttribute_Format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //$NON-NLS-1$ + comment_creation_ts_Format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //$NON-NLS-1$ + attachment_creation_ts_Format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //$NON-NLS-1$ + + delta_ts_Format_Timezone = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz"); //$NON-NLS-1$ + creation_ts_Format_Timezone = new SimpleDateFormat("yyyy-MM-dd HH:mm zzz"); //$NON-NLS-1$ + deadline_Format_Timezone = new SimpleDateFormat("yyyy-MM-dd zzz"); //$NON-NLS-1$ + customAttribute_Format_Timezone = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz"); //$NON-NLS-1$ + comment_creation_ts_Format_Timezone = new SimpleDateFormat("yyyy-MM-dd HH:mm zzz"); //$NON-NLS-1$ + attachment_creation_ts_Format_Timezone = new SimpleDateFormat("yyyy-MM-dd HH:mm zzz"); //$NON-NLS-1$ } @Override @@ -93,20 +112,38 @@ Date parsedDate = null; try { if (attributeId.equals(BugzillaAttribute.DELTA_TS.getKey())) { - parsedDate = new SimpleDateFormat(delta_ts_format).parse(dateString); + parsedDate = delta_ts_Format_Timezone.parse(dateString); } else if (attributeId.equals(BugzillaAttribute.CREATION_TS.getKey())) { - parsedDate = new SimpleDateFormat(creation_ts_format).parse(dateString); + parsedDate = creation_ts_Format_Timezone.parse(dateString); } else if (attributeId.equals(BugzillaAttribute.BUG_WHEN.getKey())) { - parsedDate = new SimpleDateFormat(comment_creation_ts_format).parse(dateString); + parsedDate = comment_creation_ts_Format_Timezone.parse(dateString); } else if (attributeId.equals(BugzillaAttribute.DATE.getKey())) { - parsedDate = new SimpleDateFormat(attachment_creation_ts_format).parse(dateString); + parsedDate = attachment_creation_ts_Format_Timezone.parse(dateString); } else if (attributeId.equals(BugzillaAttribute.DEADLINE.getKey())) { - parsedDate = new SimpleDateFormat(deadline_format).parse(dateString); + parsedDate = deadline_Format_Timezone.parse(dateString); } else if (attributeId.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) { - parsedDate = new SimpleDateFormat(customAttribute_format).parse(dateString); + parsedDate = customAttribute_Format_Timezone.parse(dateString); } } catch (ParseException e) { - return null; + try { + if (attributeId.equals(BugzillaAttribute.DELTA_TS.getKey())) { + parsedDate = delta_ts_Format.parse(dateString); + } else if (attributeId.equals(BugzillaAttribute.CREATION_TS.getKey())) { + parsedDate = creation_ts_Format.parse(dateString); + } else if (attributeId.equals(BugzillaAttribute.BUG_WHEN.getKey())) { + parsedDate = comment_creation_ts_Format.parse(dateString); + } else if (attributeId.equals(BugzillaAttribute.DATE.getKey())) { + parsedDate = attachment_creation_ts_Format.parse(dateString); + } else if (attributeId.equals(BugzillaAttribute.DEADLINE.getKey())) { + parsedDate = deadline_Format.parse(dateString); + } else if (attributeId.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) { + parsedDate = customAttribute_Format.parse(dateString); + } + } catch (ParseException e1) { + return null; + } catch (NumberFormatException e1) { + return null; + } } catch (NumberFormatException e) { return null; } @@ -120,17 +157,17 @@ String attributeId = attribute.getId(); if (attributeId.equals(BugzillaAttribute.DELTA_TS.getKey())) { - dateString = new SimpleDateFormat(delta_ts_format).format(date); + dateString = delta_ts_Format.format(date); } else if (attributeId.equals(BugzillaAttribute.CREATION_TS.getKey())) { - dateString = new SimpleDateFormat(creation_ts_format).format(date); + dateString = creation_ts_Format.format(date); } else if (attributeId.equals(BugzillaAttribute.BUG_WHEN.getKey())) { - dateString = new SimpleDateFormat(comment_creation_ts_format).format(date); + dateString = comment_creation_ts_Format.format(date); } else if (attributeId.equals(BugzillaAttribute.DATE.getKey())) { - dateString = new SimpleDateFormat(attachment_creation_ts_format).format(date); + dateString = attachment_creation_ts_Format.format(date); } else if (attributeId.equals(BugzillaAttribute.DEADLINE.getKey())) { - dateString = new SimpleDateFormat(deadline_format).format(date); + dateString = deadline_Format.format(date); } else if (attributeId.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) { - dateString = new SimpleDateFormat(customAttribute_format).format(date); + dateString = customAttribute_Format.format(date); } if (dateString == null) {