Author: jacopoc
Date: Tue Jun 19 01:08:53 2007 New Revision: 548646 URL: http://svn.apache.org/viewvc?view=rev&rev=548646 Log: Applied patch by Adrian Crum to implement User Time Zone Selection Capability. OFBIZ-1079 Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java ofbiz/trunk/framework/common/config/general.properties ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java ofbiz/trunk/framework/common/webcommon/includes/header.ftl ofbiz/trunk/framework/security/entitydef/entitymodel.xml ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java?view=diff&rev=548646&r1=548645&r2=548646 ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java Tue Jun 19 01:08:53 2007 @@ -24,8 +24,11 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Date; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -192,13 +195,7 @@ } public static java.sql.Timestamp getDayStart(java.sql.Timestamp stamp, int daysLater) { - Calendar tempCal = Calendar.getInstance(); - tempCal.setTime(new java.util.Date(stamp.getTime())); - tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); - tempCal.add(Calendar.DAY_OF_MONTH, daysLater); - java.sql.Timestamp retStamp = new java.sql.Timestamp(tempCal.getTime().getTime()); - retStamp.setNanos(0); - return retStamp; + return getDayStart(stamp, daysLater, TimeZone.getDefault(), Locale.getDefault()); } public static java.sql.Timestamp getNextDayStart(java.sql.Timestamp stamp) { @@ -210,13 +207,7 @@ } public static java.sql.Timestamp getDayEnd(java.sql.Timestamp stamp, int daysLater) { - Calendar tempCal = Calendar.getInstance(); - tempCal.setTime(new java.util.Date(stamp.getTime())); - tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 23, 59, 59); - tempCal.add(Calendar.DAY_OF_MONTH, daysLater); - java.sql.Timestamp retStamp = new java.sql.Timestamp(tempCal.getTime().getTime()); - retStamp.setNanos(999999999); - return retStamp; + return getDayEnd(stamp, daysLater, TimeZone.getDefault(), Locale.getDefault()); } /** @@ -237,15 +228,7 @@ return getYearStart(stamp, daysLater, 0, yearsLater); } public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, int daysLater, int monthsLater, int yearsLater) { - Calendar tempCal = Calendar.getInstance(); - tempCal.setTime(new java.util.Date(stamp.getTime())); - tempCal.set(tempCal.get(Calendar.YEAR), Calendar.JANUARY, 1, 0, 0, 0); - tempCal.add(Calendar.YEAR, yearsLater); - tempCal.add(Calendar.MONTH, monthsLater); - tempCal.add(Calendar.DAY_OF_MONTH, daysLater); - java.sql.Timestamp retStamp = new java.sql.Timestamp(tempCal.getTime().getTime()); - retStamp.setNanos(0); - return retStamp; + return getYearStart(stamp, daysLater, monthsLater, yearsLater, TimeZone.getDefault(), Locale.getDefault()); } public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, Number daysLater, Number monthsLater, Number yearsLater) { return getYearStart(stamp, (daysLater == null ? 0 : daysLater.intValue()), @@ -267,14 +250,7 @@ } public static java.sql.Timestamp getMonthStart(java.sql.Timestamp stamp, int daysLater, int monthsLater) { - Calendar tempCal = Calendar.getInstance(); - tempCal.setTime(new java.util.Date(stamp.getTime())); - tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), 1, 0, 0, 0); - tempCal.add(Calendar.DAY_OF_MONTH, daysLater); - tempCal.add(Calendar.MONTH, monthsLater); - java.sql.Timestamp retStamp = new java.sql.Timestamp(tempCal.getTime().getTime()); - retStamp.setNanos(0); - return retStamp; + return getMonthStart(stamp, daysLater, monthsLater, TimeZone.getDefault(), Locale.getDefault()); } /** @@ -292,27 +268,11 @@ } public static java.sql.Timestamp getWeekStart(java.sql.Timestamp stamp, int daysLater, int weeksLater) { - Calendar tempCal = Calendar.getInstance(); - tempCal.setTime(new java.util.Date(stamp.getTime())); - tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); - tempCal.add(Calendar.DAY_OF_MONTH, daysLater); - tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek()); - tempCal.add(Calendar.WEEK_OF_MONTH, weeksLater); - java.sql.Timestamp retStamp = new java.sql.Timestamp(tempCal.getTime().getTime()); - retStamp.setNanos(0); - return retStamp; + return getWeekStart(stamp, daysLater, weeksLater, TimeZone.getDefault(), Locale.getDefault()); } public static java.sql.Timestamp getWeekEnd(java.sql.Timestamp stamp) { - Calendar tempCal = Calendar.getInstance(); - tempCal.setTime(new java.util.Date(stamp.getTime())); - tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); - tempCal.add(Calendar.WEEK_OF_MONTH, 1); - tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek()); - tempCal.add(Calendar.SECOND, -1); - java.sql.Timestamp retStamp = new java.sql.Timestamp(tempCal.getTime().getTime()); - retStamp.setNanos(0); - return retStamp; + return getWeekEnd(stamp, TimeZone.getDefault(), Locale.getDefault()); } public static java.util.Calendar toCalendar(java.sql.Timestamp stamp) { @@ -744,8 +704,7 @@ * @return A int containing the week number */ public static int weekNumber(Timestamp input) { - Calendar calendar = Calendar.getInstance(); - return weekNumber(input, calendar.getFirstDayOfWeek()); + return weekNumber(input, TimeZone.getDefault(), Locale.getDefault()); } public static int weekNumber(Timestamp input, int startOfWeek) { @@ -943,6 +902,44 @@ DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale); dateFormat.setTimeZone(tz); return dateFormat.format(stamp); + } + + protected static List availableTimeZoneList = null; + /** Returns a List of available TimeZone objects. + * @see java.util.TimeZone + */ + public static List availableTimeZones() { + if (availableTimeZoneList == null) { + synchronized(UtilDateTime.class) { + if (availableTimeZoneList == null) { + availableTimeZoneList = new LinkedList(); + List idList = null; + String tzString = UtilProperties.getPropertyValue("general", "timeZones.available"); + if (tzString != null && tzString.length() > 0) { + idList = StringUtil.split(tzString, ","); + } else { + idList = Arrays.asList(TimeZone.getAvailableIDs()); + } + for (Iterator i = idList.iterator(); i.hasNext();) { + TimeZone curTz = TimeZone.getTimeZone((String)i.next()); + availableTimeZoneList.add(curTz); + } + } + } + } + return availableTimeZoneList; + } + + /** Returns a TimeZone object based upon a time zone ID. Method defaults to + * server's time zone if tzID is null or empty. + * @see java.util.TimeZone + */ + public static TimeZone toTimeZone(String tzId) { + if (UtilValidate.isEmpty(tzId)) { + return TimeZone.getDefault(); + } else { + return TimeZone.getTimeZone(tzId); + } } } Modified: ofbiz/trunk/framework/common/config/general.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/general.properties?view=diff&rev=548646&r1=548645&r2=548646 ============================================================================== --- ofbiz/trunk/framework/common/config/general.properties (original) +++ ofbiz/trunk/framework/common/config/general.properties Tue Jun 19 01:08:53 2007 @@ -26,8 +26,11 @@ # -- the default decimal format for currency currency.decimal.format=##0.00 -# -- locales made available separated by comma's +# -- locales made available separated by commas #locales.available=en,fr,nl + +# -- time zone IDs made available separated by commas +#timeZones.available=US/Eastern,US/Central,US/Mountain,US/Pacific,US/Alaska,US/Hawaii # -- the default country for drop downs country.geo.id.default=USA Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java?view=diff&rev=548646&r1=548645&r2=548646 ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java Tue Jun 19 01:08:53 2007 @@ -187,6 +187,31 @@ } } } + return setSessionTimeZone(request, response); + } + + /** Simple event to set the user's per-session time zone setting. */ + public static String setSessionTimeZone(HttpServletRequest request, HttpServletResponse response) { + String tzString = request.getParameter("tzId"); + if (UtilValidate.isNotEmpty(tzString)) { + + // update the UserLogin object + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + if (userLogin == null) { + userLogin = (GenericValue) request.getSession().getAttribute("autoUserLogin"); + } + + if (userLogin != null) { + GenericValue ulUpdate = GenericValue.create(userLogin); + ulUpdate.set("lastTimeZone", tzString); + try { + ulUpdate.store(); + userLogin.refreshFromCache(); + } catch (GenericEntityException e) { + Debug.logWarning(e, module); + } + } + } return "success"; } Modified: ofbiz/trunk/framework/common/webcommon/includes/header.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/webcommon/includes/header.ftl?view=diff&rev=548646&r1=548645&r2=548646 ============================================================================== --- ofbiz/trunk/framework/common/webcommon/includes/header.ftl (original) +++ ofbiz/trunk/framework/common/webcommon/includes/header.ftl Tue Jun 19 01:08:53 2007 @@ -68,19 +68,32 @@ ${uiLabelMap.CommonWelcome}! </#if> </p> - <p>${Static["org.ofbiz.base.util.UtilDateTime"].nowTimestamp().toString()}</p> + <#assign nowStamp = Static["org.ofbiz.base.util.UtilDateTime"].nowTimestamp()> + <#assign timeZone = Static["org.ofbiz.base.util.UtilDateTime"].toTimeZone((userLogin.lastTimeZone)?default(""))> + <p>${Static["org.ofbiz.base.util.UtilDateTime"].timeStampToString(nowStamp, timeZone, locale)}</p> <form method="post" action="<@ofbizUrl>setSessionLocale</@ofbizUrl>"> <select name="locale"> + <option value="${locale.toString()}">${locale.getDisplayName(locale)}</option> + <option value="${locale.toString()}"></option> <#list availableLocales as availableLocale> <#assign langAttr = availableLocale.toString()?replace("_", "-")> <#assign langDir = "ltr"> <#if "ar.iw"?contains(langAttr?substring(0, 2))> <#assign langDir = "rtl"> </#if> - <option lang="${langAttr}" dir="${langDir}" value="${availableLocale.toString()}"<#if locale.toString() = availableLocale.toString()> selected="selected"</#if>>${availableLocale.getDisplayName(availableLocale)}</option> + <option lang="${langAttr}" dir="${langDir}" value="${availableLocale.toString()}">${availableLocale.getDisplayName(availableLocale)}</option> </#list> </select> <input type="submit" value="${uiLabelMap.CommonSet}"/> + <br /> + <#assign displayStyle = Static["java.util.TimeZone"].LONG> + <select name="tzId"> + <option value="${timeZone.getID()}">${timeZone.getDisplayName(timeZone.useDaylightTime(), displayStyle, locale)}</option> + <option value="${timeZone.getID()}"></option> + <#list availableTimeZones as availableTz> + <option value="${availableTz.getID()}">${availableTz.getDisplayName(availableTz.useDaylightTime(), displayStyle, locale)}</option> + </#list> + </select> </form> </li> </ul> Modified: ofbiz/trunk/framework/security/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/security/entitydef/entitymodel.xml?view=diff&rev=548646&r1=548645&r2=548646 ============================================================================== --- ofbiz/trunk/framework/security/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/framework/security/entitydef/entitymodel.xml Tue Jun 19 01:08:53 2007 @@ -71,6 +71,7 @@ <field name="hasLoggedOut" type="indicator"></field> <field name="lastCurrencyUom" type="id"></field> <field name="lastLocale" type="very-short"></field> + <field name="lastTimeZone" type="id-long"></field> <field name="disabledDateTime" type="date-time"></field> <field name="successiveFailedLogins" type="numeric"></field> <prim-key field="userLoginId"/> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java?view=diff&rev=548646&r1=548645&r2=548646 ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java Tue Jun 19 01:08:53 2007 @@ -123,8 +123,9 @@ // make sure the "nullField" object is in there for entity ops; note this is nullField and not null because as null causes problems in FreeMarker and such... context.put("nullField", GenericEntity.NULL_FIELD); - // get all locale information + // get all locale & time zone information context.put("availableLocales", UtilMisc.availableLocales()); + context.put("availableTimeZones", UtilDateTime.availableTimeZones()); context.put("parameters", parameters); context.put("delegator", delegator); |
Free forum by Nabble | Edit this page |