Applied patch by Adrian Crum to implement User Time Zone Selection Capability.
OFBIZ-1079 git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@548646 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -24,8 +24,11 @@ import java.text.DecimalFormat;
|
||||
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 class UtilDateTime {
|
||||
}
|
||||
|
||||
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 class UtilDateTime {
|
||||
}
|
||||
|
||||
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 @@ public class UtilDateTime {
|
||||
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 class UtilDateTime {
|
||||
}
|
||||
|
||||
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 class UtilDateTime {
|
||||
}
|
||||
|
||||
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 @@ public class UtilDateTime {
|
||||
* @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) {
|
||||
@@ -945,4 +904,42 @@ public class UtilDateTime {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,9 +26,12 @@ currency.uom.id.default=USD
|
||||
# -- 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
|
||||
|
||||
|
||||
@@ -187,6 +187,31 @@ public class CommonEvents {
|
||||
}
|
||||
}
|
||||
}
|
||||
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";
|
||||
}
|
||||
|
||||
|
||||
@@ -68,19 +68,32 @@ under the License.
|
||||
${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>
|
||||
|
||||
@@ -71,6 +71,7 @@ under the License.
|
||||
<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"/>
|
||||
|
||||
@@ -123,8 +123,9 @@ public class ScreenRenderer {
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user