Do not use America/New_York as the default timezone for the first new user (subsequent users take as default the one from the user creating the new user), but take the one configured for the server using java.util.TimeZone.getDefaultTimeZone(). As the rhnTimeZone table does not contain all timezones, but one per offset, we take the first one that matches the offset.
Duncan
>From bc80a6ff58aa2926dc01b8a4d6aaf80fce837a56 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P <dmacvi...@suse.de> Date: Fri, 8 Mar 2013 16:06:01 +0100 Subject: [PATCH] Do not use America/New_York as the default timezone for the first new user (subsequent users take as default the one from the user creating the new user), but take the one configured for the server using java.util.TimeZone.getDefaultTimeZone(). As the rhnTimeZone table does not contain all timezones, but one per offset, we take the first one that matches the offset. Conflicts: java/code/src/com/redhat/rhn/domain/user/UserFactory.java --- .../code/src/com/redhat/rhn/domain/user/UserFactory.java | 16 ++++++++++++++++ .../com/redhat/rhn/domain/user/test/UserFactoryTest.java | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/java/code/src/com/redhat/rhn/domain/user/UserFactory.java b/java/code/src/com/redhat/rhn/domain/user/UserFactory.java index 36e5808..80ea266 100644 --- a/java/code/src/com/redhat/rhn/domain/user/UserFactory.java +++ b/java/code/src/com/redhat/rhn/domain/user/UserFactory.java @@ -44,6 +44,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.TimeZone; /** * UserFactory - the singleton class used to fetch and store @@ -501,6 +502,20 @@ public class UserFactory extends HibernateFactory { * @return US Eastern Time Zone */ public static RhnTimeZone getDefaultTimeZone() { + RhnTimeZone sysDefault = getTimeZone(TimeZone.getDefault().getID()); + if (sysDefault != null) { + return sysDefault; + } + Session session = HibernateFactory.getSession(); + List<RhnTimeZone> allTimeZones = + session.getNamedQuery("RhnTimeZone.loadAll").list(); + for (RhnTimeZone tz : allTimeZones) { + if (TimeZone.getDefault().getRawOffset() == TimeZone.getTimeZone( + tz.getOlsonName()).getRawOffset()) { + return tz; + } + } + // This should not happen unless the timezone table is incomplete return getTimeZone("America/New_York"); } @@ -522,6 +537,7 @@ public class UserFactory extends HibernateFactory { //All other timezones are sorted West to East based on raw off-set. if (timeZones != null) { Collections.sort(timeZones, new Comparator() { + @Override public int compare(Object o1, Object o2) { int offSet1 = ((RhnTimeZone)o1).getTimeZone().getRawOffset(); int offSet2 = ((RhnTimeZone)o2).getTimeZone().getRawOffset(); diff --git a/java/code/src/com/redhat/rhn/domain/user/test/UserFactoryTest.java b/java/code/src/com/redhat/rhn/domain/user/test/UserFactoryTest.java index 0117caf..e6f0bcf 100644 --- a/java/code/src/com/redhat/rhn/domain/user/test/UserFactoryTest.java +++ b/java/code/src/com/redhat/rhn/domain/user/test/UserFactoryTest.java @@ -42,6 +42,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; +import java.util.TimeZone; /** JUnit test case for the User * class. @@ -51,6 +52,7 @@ import java.util.List; public class UserFactoryTest extends RhnBaseTestCase { private UserFactory factory; + @Override public void setUp() { factory = UserFactory.getInstance(); } @@ -176,7 +178,7 @@ public class UserFactoryTest extends RhnBaseTestCase { public void testGetTimeZoneDefault() { RhnTimeZone tz = UserFactory.getDefaultTimeZone(); assertNotNull(tz); - assertTrue(tz.getOlsonName().equals("America/New_York")); + assertTrue(tz.getTimeZone().getRawOffset() == TimeZone.getDefault().getRawOffset()); } public void testTimeZoneLookupAll() { -- 1.8.1.4
_______________________________________________ Spacewalk-devel mailing list Spacewalk-devel@redhat.com https://www.redhat.com/mailman/listinfo/spacewalk-devel