Boost-Graph
view release on metacpan or search on metacpan
include/boost/date_time/local_time/posix_time_zone.hpp view on Meta::CPAN
else{
// default
dst_offsets_.dst_start_offset_ = posix_time::hours(2);
}
// start/end offsets must fall on given date
if(dst_offsets_.dst_start_offset_ < time_duration_type(0,0,0) ||
dst_offsets_.dst_start_offset_ >= time_duration_type(24,0,0))
{
throw bad_offset(posix_time::to_simple_string(dst_offsets_.dst_start_offset_));
}
// ending offset
if(eit != et_tok.end()){
dst_offsets_.dst_end_offset_ = posix_time::duration_from_string(*eit);
}
else{
// default
dst_offsets_.dst_end_offset_ = posix_time::hours(2);
}
// start/end offsets must fall on given date
if(dst_offsets_.dst_end_offset_ < time_duration_type(0,0,0) ||
dst_offsets_.dst_end_offset_ >= time_duration_type(24,0,0))
{
throw bad_offset(posix_time::to_simple_string(dst_offsets_.dst_end_offset_));
}
}
/* Parses out a start/end date spec from a posix time zone string.
* Date specs come in three possible formats, this function handles
* the 'M' spec. Ex "M2.2.4" => 2nd month, 2nd week, 4th day .
*/
void M_func(const std::string& s, const std::string& e){
typedef gregorian::nth_kday_of_month nkday;
unsigned short sm=0,sw=0,sd=0,em=0,ew=0,ed=0; // start/end month,week,day
char_separator<char> sep("M.");
tokenizer stok(s, sep), etok(e, sep);
tokenizer::iterator it = stok.begin();
sm = lexical_cast<unsigned short>(*it++);
sw = lexical_cast<unsigned short>(*it++);
sd = lexical_cast<unsigned short>(*it);
it = etok.begin();
em = lexical_cast<unsigned short>(*it++);
ew = lexical_cast<unsigned short>(*it++);
ed = lexical_cast<unsigned short>(*it);
dst_calc_rules_ = shared_ptr<dst_calc_rule>(
new nth_kday_dst_rule(
nth_last_dst_rule::start_rule(
static_cast<nkday::week_num>(sw),sd,sm),
nth_last_dst_rule::start_rule(
static_cast<nkday::week_num>(ew),ed,em)
)
);
}
//! Julian day. Feb29 is never counted, even in leap years
// expects range of 1-365
void julian_no_leap(const std::string& s, const std::string& e){
typedef gregorian::gregorian_calendar calendar;
const unsigned short year = 2001; // Non-leap year
unsigned short sm=1;
int sd=0;
sd = lexical_cast<int>(s.substr(1)); // skip 'J'
while(sd >= calendar::end_of_month_day(year,sm)){
sd -= calendar::end_of_month_day(year,sm++);
}
unsigned short em=1;
int ed=0;
ed = lexical_cast<int>(e.substr(1)); // skip 'J'
while(ed > calendar::end_of_month_day(year,em)){
ed -= calendar::end_of_month_day(year,em++);
}
dst_calc_rules_ = shared_ptr<dst_calc_rule>(
new partial_date_dst_rule(
partial_date_dst_rule::start_rule(
sd, static_cast<date_time::months_of_year>(sm)),
partial_date_dst_rule::end_rule(
ed, static_cast<date_time::months_of_year>(em))
)
);
}
//! Julian day. Feb29 is always counted, but exception thrown in non-leap years
// expects range of 0-365
void julian_day(const std::string& s, const std::string& e){
int sd=0, ed=0;
sd = lexical_cast<int>(s);
ed = lexical_cast<int>(e);
dst_calc_rules_ = shared_ptr<dst_calc_rule>(
new partial_date_dst_rule(
partial_date_dst_rule::start_rule(++sd),// args are 0-365
partial_date_dst_rule::end_rule(++ed) // pd expects 1-366
)
);
}
//! helper function used when throwing exceptions
static std::string td_as_string(const time_duration_type& td)
{
std::string s;
#if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
s = posix_time::to_simple_string(td);
#else
std::stringstream ss;
ss << td;
s = ss.str();
#endif
return s;
}
};
} } // namespace boost::local_time
#endif // _DATE_TIME_POSIX_TIME_ZONE__
( run in 1.232 second using v1.01-cache-2.11-cpan-39bf76dae61 )