OCILIB (C and C++ Driver for Oracle)  4.0.0
ocilib::Timestamp Class Reference

Object identifying the SQL data type TIMESTAMP. More...

#include <ocilib.hpp>

Inherits ocilib::HandleHolder< OCI_Timestamp * >.

Public Types

enum  TimestampTypeValues { NoTimeZone = OCI_TIMESTAMP, WithTimeZone = OCI_TIMESTAMP_TZ, WithLocalTimeZone = OCI_TIMESTAMP_LTZ }
 Interval types enumerated values. More...
 
typedef Enum< TimestampTypeValuesTimestampType
 Type of Exception. More...
 

Public Member Functions

TimestampType GetType () const
 Return the type of the given timestamp object.
 
void Convert (const Timestamp &other)
 Convert the current timestamp to the type of the given timestamp. More...
 
bool IsValid () const
 Check if the given timestamp is valid.
 
int GetYear () const
 Return the timestamp year value.
 
void SetYear (int value)
 Set the timestamp year value.
 
int GetMonth () const
 Return the timestamp month value.
 
void SetMonth (int value)
 Set the timestamp month value.
 
int GetDay () const
 Return the timestamp day value.
 
void SetDay (int value)
 Set the timestamp day value.
 
int GetHours () const
 Return the timestamp hours value.
 
void SetHours (int value)
 Set the timestamp hours value.
 
int GetMinutes () const
 Return the timestamp minutes value.
 
void SetMinutes (int value)
 Set the timestamp minutes value.
 
int GetSeconds () const
 Return the timestamp seconds value.
 
void SetSeconds (int value)
 Set the timestamp seconds value.
 
int GetMilliSeconds () const
 Return the timestamp seconds value.
 
void SetMilliSeconds (int value)
 Set the timestamp milliseconds value.
 
void GetDate (int &year, int &month, int &day) const
 Extract the date parts. More...
 
void GetTime (int &hour, int &min, int &sec, int &fsec) const
 Extract time parts. More...
 
void SetDate (int year, int month, int day)
 Set the date part. More...
 
void SetTime (int hour, int min, int sec, int fsec)
 Set the time part. More...
 
void GetDateTime (int &year, int &month, int &day, int &hour, int &min, int &sec, int &fsec) const
 Extract date and time parts. More...
 
void SetDateTime (int year, int month, int day, int hour, int min, int sec, int fsec, const ostring &timeZone=OTEXT(""))
 Set the timestamp value from given date time parts. More...
 
ostring GetTimeZone () const
 Return the name of the current time zone. More...
 
void SetTimeZone (const ostring &timeZone)
 Set the given time zone to the timestamp. More...
 
void GetTimeZoneOffset (int &hour, int &min) const
 Return the time zone (hour, minute) offsets. More...
 
void SysTimestamp ()
 Assign the current system timestamp to the current timestamp object.
 
void FromString (const ostring &data, const ostring &format=OCI_STRING_FORMAT_DATE)
 Assign to the timestamp object the value provided by the input date time string. More...
 
ostring ToString (const ostring &format=OCI_STRING_FORMAT_DATE, int precision=0) const
 Convert the timestamp value to a string. More...
 
Timestamp Clone () const
 Clone the current instance to a new one performing deep copy.
 
 operator ostring () const
 Convenient operator converting the timestamp value to a string. More...
 
Timestampoperator++ ()
 Increment the timestamp by 1 day.
 
Timestamp operator++ (int)
 Increment the timestamp by 1 day.
 
Timestampoperator-- ()
 Decrement the Timestamp by 1 day.
 
Timestamp operator-- (int)
 Decrement the Timestamp by 1 day.
 
Timestamp operator+ (int value)
 Return a new Timestamp holding the current Timestamp value incremented by the given number of days.
 
Timestamp operator- (int value)
 Return a new Timestamp holding the current Timestamp value decremented by the given number of days.
 
Interval operator- (const Timestamp &other)
 Return an interval storing the difference between the current timestamp and the given one.
 
Timestampoperator+= (int value)
 Increment the Timestamp by the given number of days.
 
Timestampoperator-= (int value)
 Decrement the Timestamp by the given number of days.
 
Timestamp operator+ (const Interval &other)
 Return a new Timestamp holding the sum of the current Timestamp value and the given Interval value.
 
Timestamp operator- (const Interval &other)
 Return a new Timestamp holding the difference of the current Timestamp value and the given Interval value.
 
Timestampoperator+= (const Interval &other)
 Increment the current Value with the given Interval value.
 
Timestampoperator-= (const Interval &other)
 Decrement the current Value with the given Interval value.
 
bool operator== (const Timestamp &other) const
 Indicates if the current Timestamp value is equal to the given Timestamp value.
 
bool operator!= (const Timestamp &other) const
 Indicates if the current Timestamp value is not equal the given Timestamp value.
 
bool operator> (const Timestamp &other) const
 Indicates if the current Timestamp value is superior to the given Timestamp value.
 
bool operator< (const Timestamp &other) const
 Indicates if the current Timestamp value is inferior to the given Timestamp value.
 
bool operator>= (const Timestamp &other) const
 Indicates if the current Timestamp value is superior or equal to the given Timestamp value.
 
bool operator<= (const Timestamp &other) const
 Indicates if the current Timestamp value is inferior or equal to the given Timestamp value.
 

Detailed Description

Object identifying the SQL data type TIMESTAMP.

This class wraps the OCILIB object handle OCI_Timestamp and its related methods

Definition at line 3089 of file ocilib.hpp.

Member Typedef Documentation

Type of Exception.

Possible values are Timestamp::TimestampTypeValues

Definition at line 3124 of file ocilib.hpp.

Member Enumeration Documentation

Interval types enumerated values.

Enumerator
NoTimeZone 

Timestamp does not contains any time zone information

WithTimeZone 

Timestamp contains a given time zone

WithLocalTimeZone 

Timestamp contains the user's local session time zone

Definition at line 3107 of file ocilib.hpp.

Member Function Documentation

void ocilib::Timestamp::Convert ( const Timestamp other)
inline

Convert the current timestamp to the type of the given timestamp.

Parameters
other- Timestamp to use for the type conversion

Definition at line 1958 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_TimestampConvert().

void ocilib::Timestamp::GetDate ( int &  year,
int &  month,
int &  day 
) const
inline

Extract the date parts.

Parameters
year- Place holder for year value
month- Place holder for month value
day- Place holder for day value

Definition at line 2087 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_TimestampGetDate().

Referenced by GetDay(), GetMonth(), GetYear(), SetDay(), SetMonth(), and SetYear().

void ocilib::Timestamp::GetTime ( int &  hour,
int &  min,
int &  sec,
int &  fsec 
) const
inline

Extract time parts.

Parameters
hour- Place holder for hour value
min- Place holder for minute value
sec- Place holder for second value
fsec- Place holder for fractional part of the seconds

Definition at line 2092 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_TimestampGetTime().

Referenced by GetHours(), GetMilliSeconds(), GetMinutes(), GetSeconds(), SetHours(), SetMilliSeconds(), SetMinutes(), and SetSeconds().

void ocilib::Timestamp::SetDate ( int  year,
int  month,
int  day 
)
inline

Set the date part.

Parameters
year- Year value
month- Month value
day- Day value

Definition at line 2102 of file ocilib_impl.hpp.

References GetDateTime(), and SetDateTime().

Referenced by SetDay(), SetMonth(), and SetYear().

void ocilib::Timestamp::SetTime ( int  hour,
int  min,
int  sec,
int  fsec 
)
inline

Set the time part.

Parameters
hour- Hour value
min- Minute value
sec- Second value
fsec- Place holder for fractional part of the seconds

Definition at line 2110 of file ocilib_impl.hpp.

References GetDateTime(), and SetDateTime().

Referenced by SetHours(), SetMilliSeconds(), SetMinutes(), and SetSeconds().

void ocilib::Timestamp::GetDateTime ( int &  year,
int &  month,
int &  day,
int &  hour,
int &  min,
int &  sec,
int &  fsec 
) const
inline

Extract date and time parts.

Parameters
year- Place holder for year value
month- Place holder for month value
day- Place holder for day value
hour- Place holder for hour value
min- Place holder for minute value
sec- Place holder for second value
fsec- Place holder for fractional part of the seconds

Definition at line 2097 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_TimestampGetDateTime().

Referenced by SetDate(), SetTime(), and SetTimeZone().

void ocilib::Timestamp::SetDateTime ( int  year,
int  month,
int  day,
int  hour,
int  min,
int  sec,
int  fsec,
const ostring timeZone = OTEXT("") 
)
inline

Set the timestamp value from given date time parts.

Parameters
year- Year value
month- Month value
day- Day value
hour- Hour value
min- Minutes value
sec- Seconds value
fsec- Fractional part of seconds value
timeZone- name of a time zone to use [optional]

Definition at line 1953 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_TimestampConstruct().

Referenced by SetDate(), SetTime(), and SetTimeZone().

ostring ocilib::Timestamp::GetTimeZone ( ) const
inline

Return the name of the current time zone.

Warning
Returns an empty string if the timestamp type is TimeStamp::NoTimeZone

Definition at line 2129 of file ocilib_impl.hpp.

References ocilib::Check(), GetType(), ocilib::MakeString(), NoTimeZone, and OCI_TimestampGetTimeZoneName().

void ocilib::Timestamp::SetTimeZone ( const ostring timeZone)
inline

Set the given time zone to the timestamp.

Warning
  • The timestamp must have a valid value before setting the timezone
  • Applies to TimeStamp::WithTimeZone only

Definition at line 2118 of file ocilib_impl.hpp.

References GetDateTime(), GetType(), SetDateTime(), and WithTimeZone.

void ocilib::Timestamp::GetTimeZoneOffset ( int &  hour,
int &  min 
) const
inline

Return the time zone (hour, minute) offsets.

Parameters
hour- Place holder for hour value
min- Place holder for min value

Definition at line 2147 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_TimestampGetTimeZoneOffset().

void ocilib::Timestamp::FromString ( const ostring data,
const ostring format = OCI_STRING_FORMAT_DATE 
)
inline

Assign to the timestamp object the value provided by the input date time string.

Parameters
data- String date time
format- format of the date time provided in parameter 'data'
Note
For date time formats, refer to the Oracle SQL documentation

Definition at line 2162 of file ocilib_impl.hpp.

References ocilib::Check(), and OCI_TimestampFromText().

ostring ocilib::Timestamp::ToString ( const ostring format = OCI_STRING_FORMAT_DATE,
int  precision = 0 
) const
inline

Convert the timestamp value to a string.

Parameters
format- date time / timestamp format to use
precision- precision for milliseconds
Note
For date time / timestamp formats, refer to the Oracle SQL documentation

Definition at line 2167 of file ocilib_impl.hpp.

References ocilib::Check(), ocilib::MakeString(), and OCI_TimestampToText().

ocilib::Timestamp::operator ostring ( ) const
inline

Convenient operator converting the timestamp value to a string.

Note
It calls ToString() with default date time format

Definition at line 2178 of file ocilib_impl.hpp.