in wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java [192:318]
public TimeZone getTimeZone()
{
if (timeZone == null && jsTimeZone != null)
{
TimeZone temptimeZone = TimeZone.getTimeZone(jsTimeZone);
if (jsTimeZone.equals(temptimeZone.getID()))
{
timeZone = temptimeZone;
}
}
if (timeZone == null)
{
String utc = getUtcOffset();
if (utc != null)
{
// apparently it is platform dependent on whether you get the
// offset in a decimal form or not. This parses the decimal
// form of the UTC offset, taking into account several
// possibilities
// such as getting the format in +2.5 or -1.2
int dotPos = utc.indexOf('.');
if (dotPos >= 0)
{
String hours = utc.substring(0, dotPos);
String hourPart = utc.substring(dotPos + 1);
if (hours.startsWith("+"))
{
hours = hours.substring(1);
}
int offsetHours = Integer.parseInt(hours);
int offsetMins = (int)(Double.parseDouble(hourPart) * 6);
// construct a GMT timezone offset string from the retrieved
// offset which can be parsed by the TimeZone class.
AppendingStringBuffer sb = new AppendingStringBuffer("GMT");
sb.append(offsetHours > 0 ? '+' : '-');
sb.append(Math.abs(offsetHours));
sb.append(':');
if (offsetMins < 10)
{
sb.append('0');
}
sb.append(offsetMins);
timeZone = TimeZone.getTimeZone(sb.toString());
}
else
{
int offset = Integer.parseInt(utc);
if (offset < 0)
{
utc = utc.substring(1);
}
timeZone = TimeZone.getTimeZone("GMT" + ((offset > 0) ? '+' : '-') + utc);
}
String dstOffset = getUtcDSTOffset();
if (timeZone != null && dstOffset != null)
{
TimeZone dstTimeZone;
dotPos = dstOffset.indexOf('.');
if (dotPos >= 0)
{
String hours = dstOffset.substring(0, dotPos);
String hourPart = dstOffset.substring(dotPos + 1);
if (hours.startsWith("+"))
{
hours = hours.substring(1);
}
int offsetHours = Integer.parseInt(hours);
int offsetMins = (int)(Double.parseDouble(hourPart) * 6);
// construct a GMT timezone offset string from the
// retrieved
// offset which can be parsed by the TimeZone class.
AppendingStringBuffer sb = new AppendingStringBuffer("GMT");
sb.append(offsetHours > 0 ? '+' : '-');
sb.append(Math.abs(offsetHours));
sb.append(':');
if (offsetMins < 10)
{
sb.append('0');
}
sb.append(offsetMins);
dstTimeZone = TimeZone.getTimeZone(sb.toString());
}
else
{
int offset = Integer.parseInt(dstOffset);
if (offset < 0)
{
dstOffset = dstOffset.substring(1);
}
dstTimeZone = TimeZone.getTimeZone("GMT" + ((offset > 0) ? '+' : '-') +
dstOffset);
}
// if the dstTimezone (1 July) has a different offset then
// the real time zone (1 January) try to combine the 2.
if (dstTimeZone != null &&
dstTimeZone.getRawOffset() != timeZone.getRawOffset())
{
int dstSaving = Math.abs(dstTimeZone.getRawOffset() - timeZone.getRawOffset());
String[] availableIDs = TimeZone.getAvailableIDs(dstTimeZone.getRawOffset() < timeZone.getRawOffset() ? dstTimeZone.getRawOffset() : timeZone.getRawOffset());
for (String availableID : availableIDs)
{
TimeZone zone = TimeZone.getTimeZone(availableID);
if (zone.getDSTSavings() == dstSaving)
{
// this is a best guess... still the start and end of the DST should
// be needed to know to be completely correct, or better yet
// not just the GMT offset but the TimeZone ID should be transfered
// from the browser.
timeZone = zone;
break;
}
}
}
}
}
}
return timeZone;
}