Local Time SystemIntroduction -- Usage Examples IntroductionThe library supports 4 main extensions for the management of local times. This includes
Together, these extensions define a time system adjusted for recording times related to a specific earth location. This time system utilizes all the features and benefits of the posix_time system (see posix_time for full details). It uses a time_zone object which contains all the necessary data/rules to enable adjustments to and from various time zones. The time_zone objects used in date_time are handled via a boost::shared_ptr<boost::local_time::time_zone>. The phrase "wall-clock" refers to the time that would be shown on a wall clock in a particular time zone at any point in time. Local_time uses a time zone object to account for differences in time zones and daylight savings adjustments. For example: While 5:00 pm, October 10, 2004 in Sydney Australia occurs at exactly the same instant as 3:00 am, October 10, 2004 in New York USA, it is a 14 hour difference in wall-clock times. However, a point in time just one day later will result in a 16 hour difference in wall-clock time due to daylight savings adjustments in both time zones. The local_time system tracks these by means of a time point, stored as UTC, and time_zone objects that contain all the necessary data to correctly calculate wall-clock times. Usage Examples
Introduction --
Header --
Construction --
Accessors
IntroductionThe time_zone_base class is an abstract base class template for representing time zones. Time zones are a set of data and rules that provide information about a time zone. The date_time library handles time_zones by means of a boost::shared_ptr<time_zone_base>. A user's custom time zone class will work in the date_time library by means of this shared_ptr. For convienience, the time_zone_base class is typedef'd as time_zone. All references in the documentation to time_zone, are referring to this typedef. HeaderThe time_zone_base class is defined in the header: #include "boost/date_time/time_zone_base.hpp"
ConstructionA default constructor is provided in the time_zone_base class. There are no private data members in this base class to initialize. Template parameters are time_type (typically posix_time::ptime) and CharT (defaults to char). AccessorsAll of the accessors listed here are pure virtual functions.
Introduction --
Important Notes --
Header --
Construction --
Accessors
IntroductionA posix_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 stored as a boost::shared_ptr<dst_calc_rules>. 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;
A posix_time_zone is unique in that the object is created from a Posix time zone string (IEEE Std 1003.1). A POSIX time zone string takes the form of:
'std' specifies the abbrev of the time zone. 'offset' is the offset from UTC. 'dst' specifies the abbrev of the time zone during daylight savings time. The second offset is how many hours changed during DST. 'start' and 'end' are the dates when DST goes into (and out of) effect. 'offset' takes the form of:
'time' and 'offset' take the same form. 'start' and 'end' can be one of three forms:
Exceptions will be thrown under the following conditions:
As stated above, the 'offset' and '/time' portions of the string are not required. If they are not given they default to 01:00 for 'offset', and 02:00 for both occurrences of '/time'. Some examples are:
These two are actually the same specification (defaults were used in the second string). This zone lies eight hours west of GMT and makes a one hour shift forward during daylight savings time. Daylight savings for this zone starts on the first Sunday of April at 2am, and ends on the first Sunday of October at 2am.
This zone is as simple as it gets. This zone lies seven hours west of GMT and has no daylight savings.
This string describes the time zone for Sydney Australia. It lies ten hours east of GMT and makes a one hour shift forward during daylight savings. Being located in the southern hemisphere, daylight savings begins on the last Sunday in October at 2am and ends on the last Sunday in March at 3am.
This specification describes a fictitious zone that lies three hours east of GMT. It makes a two hour shift forward for daylight savings which begins on March 1st at midnight, and ends on October 31st at 2am. The 'J' designation in the start/end specs signifies that counting starts at one and February 29th is never counted.
This specification is significant because of the '59'. The lack of 'J' for the start and end dates, indicates that the Julian day-count begins at zero and ends at 365. If you do the math, you'll see that allows for a total of 366 days. This is fine in leap years, but in non-leap years '59' (Feb-29) does not exist. This will construct a valid posix_time_zone object but an exception will be thrown if the date of '59' is accessed in a non-leap year. Ex: posix_time_zone leap_day(std::string("FST+3FDT,59,304")); leap_day.dst_local_start_time(2004); // ok leap_day.dst_local_start_time(2003); // Exception thrown
The posix_time_zone objects are used via a boost::shared_ptr<local_time::time_zone_base>. As a convenience, a typedef for boost::shared_ptr<local_time::time_zone_base> is provided: typedef boost::shared_ptr<time_zone_base> local_time::time_zone_ptr;
See Simple time zone for a side by side example of time_zone and posix_time_zone usage. Important Notes
HeaderThe 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
Accessors
Introduction --
Header --
Construction --
Accessors --
Data File Details
IntroductionThe local_time system depends on the ability to store time zone information. Our Time Zone Database (tz_database) is a means of permanently storing that data. The specifications for many time zones (377 at this time) are provided. These specifications are based on data found in the zoneinfo datebase. The specifications are stored in the file: libs/date_time/data/date_time_zonespec.csv . While this file already contains specifications for many time zones, it's real intent is for the user to modify it by adding (or removing) time zones to fit their application. See Data File Details to learn how this is accomplished. HeaderThe 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
The only constructor takes no arguments and creates an empty database. It is up to the user to populate the database. This is typically achieved by loading the desired datafile, but can also be accomplished by means of the
Accessors
Data File DetailsField Description/DetailsThe csv file containing the zone_specs used by the boost::local_time::tz_database is intended to be customized by the library user. When customizing this file (or creating your own) the file must follow a specific format. This first line is expected to contain column headings and is therefore not processed by the tz_database. Each record (line) must have eleven fields. Some of those fields can be empty. Every field (even empty ones) must be enclosed in double-quotes.
Some fields represent a length of time. The format of these fields must be:
Where the plus or minus is mandatory and the seconds are optional. Since some time zones do not use daylight savings it is not always necessary for every field in a zone_spec to contain a value. All zone_specs must have at least ID and GMT offset. Zones that use daylight savings must have all fields filled except: STD ABBR, STD NAME, DST NAME. You should take note that DST ABBR is mandatory for zones that use daylight savings (see field descriptions for further details). Field Description/Details
Introduction --
Header --
Construction --
Accessors --
Dependent Types
IntroductionA 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;
HeaderThe 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"
ConstructionConstruction 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.
Accessors
Dependent TypesTime Zone Names -- Dst Adjustment Offsets -- Daylight Savings Calc RulesTime Zone NamesThe 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>.
Dst Adjustment OffsetsThe dst_adjustment_offsets type is a collection of three time_duration objects.
Daylight Savings Calc RulesDaylight 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.
* 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.
Introduction --
Header --
Construct From Clock --
Construction --
Accessors --
Operators --
Struct tm Functions
IntroductionA local_date_time object is a point in time and an associated time zone. The time is represented internally as UTC. HeaderThe 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"
Construct From ClockCreation of a local_date_time object from clock is possible with either second, or sub second resolution.
ConstructionConstruction of a local_date_time object can be done with a ptime and a time_zone_ptr where the ptime represents UTC time. Construction with a wall-clock representation takes the form of a date, a time_duration, a time_zone_ptr, and a fourth parameter that addresses the following complication. Construction from a wall-clock rep may result in differing shifts for a particular time zone, depending on daylight savings rules for that zone. This means it is also possible to create a local_date_time with a non-existent, or duplicated, UTC representation. These cases occur during the forward shift in time that is the transition into daylight savings and during the backward shift that is the transition out of daylight savings. The user has two options for handling these cases: a bool flag that states if the time is daylight savings, or an enum that states what to do when either of these cases are encountered.
The bool flag is ignored when the given time_zone has no daylight savings specification. When the daylight savings status of a given time label is calculated and it does not match the flag, a
There are two elements in the
Accessors
Operators
Struct tm FunctionsFunction for converting a
Introduction --
Header --
Construction --
Accessors --
Operators
Introduction
The class
A period that is created with beginning and end points being equal, or with a duration of zero, is known as a zero length period. Zero length periods are considered invalid (it is perfectly legal to construct an invalid period). For these periods, the Header
#include "boost/date_time/local_time/local_time.hpp" //include all types plus i/o or #include "boost/date_time/local_time/local_time_types.hpp" //no i/o just types
Construction
Accessors
Operators
|