33 if( hours < -11 || hours > 12 )
34 throw std::runtime_error(
"timezone must be between -11 and 12" ) ;
39 std::string hours( hours_in ) ;
40 bool negative = !hours.empty() && hours.at(0U) ==
'-' ;
41 bool positive = !hours.empty() && hours.at(0U) ==
'+' ;
42 if( negative || positive ) hours.erase(0U,1U) ;
43 std::string::size_type pos = hours.find(
".") ;
51 throw std::runtime_error(
"invalid timezone: use a signed integral number of hours" ) ;
54 m_minutes =
static_cast<int>(minutes) ;
55 if( negative ) m_minutes = -m_minutes ;
60 return m_minutes == 0 ;
65 G_ASSERT( std::time_t(-1) < std::time_t(0) ) ;
66 return std::time_t(m_minutes) * 60 ;
71 unsigned int uminutes = m_minutes < 0 ?
72 static_cast<unsigned int>(-m_minutes) :
73 static_cast<unsigned int>(m_minutes) ;
75 unsigned int hh = uminutes / 60U ;
76 unsigned int mm = uminutes % 60U ;
78 std::ostringstream ss ;
79 ss << (m_minutes<0?
'-':
'+') << (hh/10U) << (hh%10U) << (mm/10U) << (mm%10U) ;
Timezone(int hours=0)
Constructor.
std::time_t seconds() const
Returns the offset as a signed number of seconds.
std::string str() const
Returns a five-character "+/-hhmm" representation.
bool zero() const
Returns true for utc.
static std::string tail(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the last part of the string after the given position.
static unsigned int toUInt(const std::string &s)
Converts string 's' to an unsigned int.
static std::string head(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the first part of the string up to just before the given position.
static bool isUInt(const std::string &s)
Returns true if the string can be converted into an unsigned integer without throwing an exception...