This class will take care of daylight saving time into the consideration and calculates the offset between the localtime and GMT.
Definition at line 66 of file timezone.h.
typedef std::vector<Interval> OSB_LIB::TimeZone::Intervals |
typedef Id<TimeZone> OSB_LIB::TimeZone::Oid |
OSB_LIB::TimeZone::TimeZone | ( | const Oid & | oid, | |
const std::string & | name, | |||
const std::string & | dstStart, | |||
const std::string & | dstStartTime, | |||
const std::string & | dstEnd, | |||
const std::string & | dstEndTime, | |||
long | stdOffset, | |||
long | dstOffset | |||
) |
Constructor to construct with all timezone informations.
This will configure this object with the given value. The dstStart and dstEnd is having the format of m.n.d where m is the month, n is the week and d is day. It means dth day of nth week in month m. If the value of n is 5 means last dth day of month m irrespective of 4 week or 5 week, d is 1 for Monday and 7 for sunday. The dstStartTime and dstEndTime is having the format of HH[:MM[:SS]].
oid | Unique object identifier for timezone. | |
name | Name of the object. | |
dstStart | Start date of the DST period. | |
dstStartTime | The time when the dst starts on the dstStart date. | |
dstEnd | End date of the DST period. | |
dstEndTime | The time when the dst ends on the dstEnd date. | |
stdOffset | Difference between the std time and GMT in seconds. | |
dstOffset | Difference between the dst time and GMT in seconds. |
Default constructor only with optional object id.
It assumes the difference between the local time and GMT as the standard offset.
oid | Unique object identifier for timezone. |
const std::string& OSB_LIB::TimeZone::dstEnd | ( | ) | const |
Returns the end date of the DST in m.n.d format.
const std::string& OSB_LIB::TimeZone::dstEndTime | ( | ) | const |
Returns the DST end time in HH[:MM[:SS]] format.
long OSB_LIB::TimeZone::dstOffset | ( | ) | const |
const std::string& OSB_LIB::TimeZone::dstStart | ( | ) | const |
Returns the start date of the DST in m.n.d format.
const std::string& OSB_LIB::TimeZone::dstStartTime | ( | ) | const |
Returns the DST start time in HH[:MM[:SS]] format.
Finds the interval for the given timestamp.
ts | The timestamp for which the offset is required. |
bool OSB_LIB::TimeZone::insert | ( | const OSB_DB::Session & | session | ) |
Insert the timezone into the database.
This will insert the timezone into the database using timezone gateway. All the attributes except object identifier should be filled before insertion. The object identifier should be assigned after the successful insertion into the database.
session | Database session to use. |
Exception | on general database error. |
const TimeZone::Intervals& OSB_LIB::TimeZone::intervals | ( | ) | const [private] |
Returns the interval array.
DateTime OSB_LIB::TimeZone::mkDateTime | ( | std::string & | dstDate, | |
std::string & | dstTime, | |||
int | year | |||
) | [private] |
It creates a datetime for the given information.
It parse the given dstDate, dstTime and configure the values to the datetime and returns the same.
dstDate | The string which is used to configure the date in the datetime. | |
dstTime | The string which is used to configure the time in the datetime. | |
year | The year to be configured in the datetime. |
DateTime OSB_LIB::TimeZone::mkDstEnd | ( | int | year | ) | [private] |
It makes the DST end period for the given year.
It use the dstEnd_, dstEndTime_ and year to make the dst end period. It uses the function mkDateTime to create this datetime for the given information.
year | The year for which the DST end period required. |
DateTime OSB_LIB::TimeZone::mkDstStart | ( | int | year | ) | [private] |
It makes the DST start period for the given year.
It use the dststart_, dstStartTime_ and year to make the dst start period. It uses the function mkDateTime to create this datetime for the given information.
year | The year for which the DST start period required. |
Makes the interval for the given datetime object.
It takes the year from the given datetime object.It creates a interval using the dstStart, dstStartTime, dstEnd and dstEndTime, dstOffset. If the given datetime is lying in this interval then this interval will be pushed into the interval container and the position will be returned. If the given datetime object is less then the interval is made for the dstEnd of previous year, the dstStart of current year and the offset is the stdOffset. This interval will be pushed into the container and the position will be returned.
ts | The datetime for which the interval has to be defined. |
const std::string& OSB_LIB::TimeZone::name | ( | ) | const |
Returns the name of the object.
void OSB_LIB::TimeZone::normalize | ( | DateTime & | ts | ) |
This will normalize the ts to STD or DST using the offset.
ts | The datetime object to use. |
Undefined | Assume the DST starts on first sunday of april and ends at first sunday of october. The time will be shifted to one hour more at the dst Start and will be back one hour at the dst end. The datetime <i>ts</i> will be normalized as follows: 7-4-2002 03:00:00 6-10-2002 01:59:59 |--------------| 1-1-2002 00:00:01 31-12-2002 00:00:00 |---------------| |----------------| 7-4-2002 01:59:59 6-10-2002 01:00:00 The line at the top is the DST time period of the year 2002 and the bottom two lines are the STD time periods. Assume DST offset = -18000, STD offset = -21600 Input 1: If the datetime <i>ts</i> is 7-4-2002 01:30:00[GMT-6:00] with offset -21600. The datetime is available in the STD time period, so it won't change the <i>ts</i>. Input 2: If the datetime <i>ts</i> is 7-4-2002 02:30:00[GMT-6:00] with offset -21600. This datetime is not exist in the STD time period. So this normalize the datetime to DST time period as 7-4-2002 03:30:00 [GMT-5:00]. Input 3: If the datetime <i>ts</i> is 7-4-2002 03:30:00[GMT-6:00] with offset -21600. This datetime is not exist in the STD time period. So this normalize the datetime to DST time period as 7-4-2002 04:30:00 [GMT-5:00]. Input 4: If the datetime <i>ts</i> is 7-4-2002 02:30:00[GMT-5:00] with the offset -18000. The datetime is not exist in the DST time period. So this will normalize to STD time period as 7-4-2002 01:30:00[GMT-6:00]. Input 5: If the datetime <i>ts</i> is 7-4-2002 03:30:00[GMT-5:00] with the offset -18000. The datetime is exist in the DST time period, so it won't change the <i>ts</i>. Input 6: If the datetime <i>ts</i> is 6-10-2002 01:30:00[GMT-5:00] with the offset -18000. The datetime is exist in the DST time period, so it won't change the <i>ts</i>. Input 7: If the datetime <i>ts</i> is 6-10-2002 02:30:00[GMT-5:00] with the offset -18000. The datetime is not exist in the DST time period so it will be normalized to the STD time period as 6-10-2002 01:30:00[GMT-6:00]. All other inputs will come in any one of the above category. |
This will return the offset to the GMT in seconds.
It finds the interval for the given datetime. If there is no interval for the given datetime then it will create a interval and returns the offset of that interval. The new offset will be assigned to ts. Existing offset will not be considered.
ts | The datetime object to use. |
Undefined |
const Oid& OSB_LIB::TimeZone::oid | ( | ) | const |
Returns the unique object identifier.
bool OSB_LIB::TimeZone::read | ( | const OSB_DB::Session & | session | ) |
Read the timezone from the database.
This will read the timezone informations from the database using timezone gateway. The object identifier is used to identify the timezone. Before calling this function the object identifier should be set. All the remaining attributes are filled from the database.
session | Database session to use. |
Exception | if object not found. |
bool OSB_LIB::TimeZone::remove | ( | const OSB_DB::Session & | session | ) |
Remove the timezone in the database.
This will remove the timezone object from the database using timezone gateway. Before executing this function the object identifier should be filled to identify the object in the database.
session | Database session to use. |
Exception | if object not found. |
long OSB_LIB::TimeZone::stdOffset | ( | ) | const |
friend struct OSB_DB::TimeZoneGw [friend] |
It fills all the private attributes on read. It will perform all the database operations for the TimeZone.
Definition at line 72 of file timezone.h.
std::string OSB_LIB::TimeZone::dstEnd_ [private] |
std::string OSB_LIB::TimeZone::dstEndTime_ [private] |
long OSB_LIB::TimeZone::dstOffset_ [private] |
std::string OSB_LIB::TimeZone::dstStart_ [private] |
std::string OSB_LIB::TimeZone::dstStartTime_ [private] |
Intervals OSB_LIB::TimeZone::intervals_ [mutable, private] |
std::string OSB_LIB::TimeZone::name_ [private] |
Oid OSB_LIB::TimeZone::oid_ [private] |
long OSB_LIB::TimeZone::stdOffset_ [private] |
Difference between the normal time and the GMT in seconds.
Definition at line 342 of file timezone.h.