const TimeZonePtr TimeZone::getTimeZone()

in src/main/cpp/timezone.cpp [201:285]


const TimeZonePtr TimeZone::getTimeZone( const LogString& id )
{
	const logchar gmt[] = { 0x47, 0x4D, 0x54, 0 };

	if ( id == gmt )
	{
		return log4cxx::helpers::TimeZoneImpl::GMTTimeZone::getInstance();
	}

	if ( id.length() >= 5 && id.substr( 0, 3 ) == gmt )
	{
		int hours = 0;
		int minutes = 0;
		int sign = 1;

		if (id[3] == 0x2D /* '-' */)
		{
			sign = -1;
		}

		LogString off( id.substr( 4 ) );

		if ( id.length() >= 7 )
		{
			size_t colonPos = off.find( 0x3A /* ':' */);

			if ( colonPos == LogString::npos )
			{
				minutes = StringHelper::toInt(off.substr(off.length() - 2));
				hours = StringHelper::toInt(off.substr(0, off.length() - 2));
			}
			else
			{
				minutes = StringHelper::toInt(off.substr(colonPos + 1));
				hours = StringHelper::toInt(off.substr(0, colonPos));
			}
		}
		else
		{
			hours = StringHelper::toInt(off);
		}

		LogString s(gmt);
		Pool p;
		LogString hh;
		StringHelper::toString(hours, p, hh);

		if (sign > 0)
		{
			s.append(1, (logchar) 0x2B /* '+' */);
		}
		else
		{
			s.append(1, (logchar) 0x2D /* '-' */);
		}

		if (hh.length() == 1)
		{
			s.append(1, (logchar) 0x30 /* '0' */);
		}

		s.append(hh);
		s.append(1, (logchar) 0x3A /*' :' */);
		LogString mm;
		StringHelper::toString(minutes, p, mm);

		if (mm.length() == 1)
		{
			s.append(1, (logchar) 0x30 /* '0' */);
		}

		s.append(mm);
		apr_int32_t offset = sign * (hours * 3600 + minutes * 60);
		return std::make_shared<helpers::TimeZoneImpl::FixedTimeZone>( s, offset );
	}

	const TimeZonePtr& ltz = getDefault();

	if ( ltz->getID() == id )
	{
		return ltz;
	}

	return getGMT();
}