Custom Time Zone
Introduction --
Header --
Construction --
Accessors --
Dependent Types
Introduction
A custom_time_zone object is a set of data and rules that provide information about a time zone. Information such as the offset from UTC, it's name and abbreviation, as well as daylight savings rules, called dst_calc_rules. These rules are handled via a boost::shared_ptr<dst_calc_rules>. Not all time zones utilize daylight savings, therefore, time_zone objects can be used with a NULL-assigned shared_ptr.
As a convenience, a typedef for shared_ptr<dst_calc_rules> is provided.
typedef boost::shared_ptr<dst_calc_rules> local_time::dst_calc_rule_ptr;
The time_zone objects are used via a boost::shared_ptr<local_time::time_zone>. As a convenience, a typedef for boost::shared_ptr<local_time::time_zone> is provided:
typedef boost::shared_ptr<time_zone> local_time::time_zone_ptr;Header
The inclusion of a single header will bring in all boost::local_time types, functions, and IO operators.
#include "boost/date_time/local_time/local_time.hpp"Construction
Construction of a custom_time_zone is dependent on four objects: a
time_duration, a time_zone_names, a dst_adjustment_offsets, and a shared_ptr to a dst_calc_rule.
SyntaxExamplecustom_time_zone(...)
Parameters:
names,
gmt_offset,
dst_offsets,
dst_rules See simple_time_zone example for time_zone usageAccessorsSyntaxDescriptionExamplestd::string dst_zone_abbrev()Returns the daylight savings abbreviation for the represented time zone.nyc_zone_sh_ptr->dst_zone_abbrev();
// "EDT"std::string std_zone_abbrev()Returns the standard abbreviation for the represented time zone.nyc_zone_sh_ptr->std_zone_abbrev();
// "EST"std::string dst_zone_name()Returns the daylight savings name for the represented time zone.nyc_zone_sh_ptr->dst_zone_name();
// "Eastern Daylight Time"std::string std_zone_name()Returns the standard name for the represented time zone.nyc_zone_sh_ptr->std_zone_name();
// "Eastern Standard Time"bool has_dst()Returns true when custom_time_zone's shared_ptr to dst_calc_rules is not NULL.nyc_zone_sh_ptr->has_dst();
// true
phx_zone_sh_ptr->has_dst();
// falsedst_local_start_time(...)
Return Type:
ptime
Parameter:
greg_yearThe date and time daylight savings time begins in given year. Returns not_a_date_time if this zone has no daylight savings.nyc_ptr->dst_local_start_time(2004);
// 2004-Apr-04 02:00dst_local_end_time(...)
Return Type:
ptime
Parameter:
greg_yearThe date and time daylight savings time ends in given year. Returns not_a_date_time if this zone has no daylight savings.nyc_ptr->dst_local_end_time(2004);
// 2004-Oct-31 02:00time_duration base_utc_offset()The amount of time offset from UTC (typically in hours).nyc_ptr->base_utc_offset();
// -05:00time_duration dst_offset()The amount of time shifted during daylight savings.nyc_zone_sh_ptr->dst_offset();
// 01:00std::string to_posix_string()Returns a posix time zone string representation of this time_zone object. Depending on how the time_zone object was created, the date-spec format of the string will be in either 'M' notation or 'n' notation. Every possible date-spec that can be represented in 'J' notation can also be represented in 'n' notation. The reverse is not true so only 'n' notation is used for these types of date-specs. For a detailed description of a posix time zone string see posix_time_zone.nyc_ptr->to_posix_string();
// "EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"
phx_ptr->to_posix_string();
// "MST-07"
Dependent Types
Time Zone Names --
Dst Adjustment Offsets --
Daylight Savings Calc Rules
Time Zone Names
The time_zone_names_base type is an immutable template class of four strings. One each for the name and abbreviation in standard time and daylight savings time. The time_zone_names type is a typedef of time_zone_names_base<char>.
SyntaxDescriptionExampletime_zone_names(...)
Parameters:
string std_name
string std_abbrev
string dst_name
string dst_abbrevThe only constructor, all four strings must be provided.string sn("Eastern Standard Time");
string sa("EST");
string dn("Eastern Daylight Time");
string da("EDT");
time_zone_names nyc_names(sn, sa,
dn, da);std::string std_zone_name()Returns the standard zone namenyc_names.std_zone_name();
// "Eastern Standard Time"std::string std_zone_abbrev()Returns the standard zone abbreviationnyc_names.std_zone_abbrev();
// "EST"std::string dst_zone_name()Returns the daylight savings zone namenyc_names.std_zone_name();
// "Eastern Daylight Time"std::string dst_zone_abbrev()Returns the daylight savings zone abbreviationnyc_names.std_zone_abbrev();
// "EDT"Dst Adjustment Offsets
The dst_adjustment_offsets type is a collection of three time_duration objects.
SyntaxDescriptionExampledst_adjustment_offsets(...)
Parameters:
time_duration dst_adjust
time_duration start_offset
time_duration end_offsetThe first time_duration is the daylight savings adjustment. The second is the time which daylight savings starts on the start day. The third is the time daylight savings ends on the ending day.
dst_adjustment_offsets(hours(1),
hours(2),
hours(2));Daylight Savings Calc Rules
Daylight savings calc rules, named dst_calc_rules, are a series of objects that group appropriate date_generators together to form rule sets. The individual rules objects are used via dst_calc_rule_ptr.
For a complete example of all five dst_calc_rule types, see: calc_rules example.
SyntaxDescriptionpartial_date_dst_rule(...)
Parameters:
start_rule
end_ruleBoth the start and end rules are of type gregorian::partial_date.first_last_dst_rule(...)
Parameters:
start_rule
end_ruleThe DST start rule is of type gregorian::first_day_of_the_week_in_month and the end rule is of type gregorian::last_day_of_the_week_in_month.last_last_dst_rule(...)
Parameters:
start_rule
end_ruleBoth the start and end rules are of type gregorian::last_day_of_the_week_in_month.nth_last_dst_rule(...)
Parameters:
start_rule
end_ruleThe DST start rule is of type gregorian::nth_day_of_the_week_in_month and the end rule is of type gregorian::last_day_of_the_week_in_month.nth_kday_dst_rule(...)
Parameters:
start_rule
end_rule)
(see note* below)Both rules are of type gregorian::nth_day_of_the_week_in_month.
* Note: The name "nth_kday_dst_rule" is a bit cryptic. Therefore, a more descriptive name, "nth_day_of_the_week_in_month_dst_rule", is also provided.