OCILIB (C and C++ Driver for Oracle)  4.7.5
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Loading...
Searching...
No Matches
ocilib::Timestamp Class Reference

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

#include <types.hpp>

Inherits ocilib::core::HandleHolder< OCI_Timestamp * >, and ocilib::core::Streamable.

Public Types

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

Public Member Functions

 Timestamp ()
 Create an empty null timestamp instance.
 
 Timestamp (TimestampType type)
 Create a new instance of the given type.
 
 Timestamp (TimestampType type, const ostring &data, const ostring &format=OTEXT(""))
 Creates a timestamp object with the value provided by the input date time string.
 
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.
 
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.
 
void GetTime (int &hour, int &min, int &sec, int &fsec) const
 Extract time parts.
 
void SetDate (int year, int month, int day)
 Set the date part.
 
void SetTime (int hour, int min, int sec, int fsec)
 Set the time part.
 
void GetDateTime (int &year, int &month, int &day, int &hour, int &min, int &sec, int &fsec) const
 Extract date and time parts.
 
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.
 
ostring GetTimeZone () const
 Return the name of the current time zone.
 
void SetTimeZone (const ostring &timeZone)
 Set the given time zone to the timestamp.
 
void GetTimeZoneOffset (int &hour, int &min) const
 Return the time zone (hour, minute) offsets.
 
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.
 
ostring ToString (const ostring &format, int precision) const
 Convert the timestamp value to a string using the given format and precision.
 
ostring ToString () const override
 Convert the timestamp value to a string using default date format and no precision.
 
Timestamp Clone () const
 Clone the current instance to a new one performing deep copy.
 
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) const
 Return a new Timestamp holding the current Timestamp value incremented by the given number of days.
 
Timestamp operator- (int value) const
 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) const
 Return a new Timestamp holding the sum of the current Timestamp value and the given Interval value.
 
Timestamp operator- (const Interval &other) const
 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.
 

Static Public Member Functions

static Timestamp SysTimestamp (TimestampType type=NoTimeZone)
 return the current system timestamp
 
static void Substract (const Timestamp &lsh, const Timestamp &rsh, Interval &result)
 Subtract the given two timestamp and store the result into the given Interval.
 

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 3509 of file types.hpp.

Member Typedef Documentation

◆ TimestampType

Type of timestamp.

Possible values are Timestamp::TimestampTypeValues

Definition at line 3544 of file types.hpp.

Member Enumeration Documentation

◆ TimestampTypeValues

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 3527 of file types.hpp.

Constructor & Destructor Documentation

◆ Timestamp() [1/3]

ocilib::Timestamp::Timestamp ( )
inline

Create an empty null timestamp instance.

Definition at line 31 of file Timestamp.hpp.

◆ Timestamp() [2/3]

ocilib::Timestamp::Timestamp ( TimestampType  type)
inline

Create a new instance of the given type.

Parameters
type- Timestamp type to create

Definition at line 35 of file Timestamp.hpp.

References ocilib::core::Check(), and OCI_TimestampCreate().

◆ Timestamp() [3/3]

ocilib::Timestamp::Timestamp ( TimestampType  type,
const ostring data,
const ostring format = OTEXT("") 
)
inline

Creates a timestamp object with the value provided by the input date time string.

Parameters
type- Timestamp type to create
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 44 of file Timestamp.hpp.

References ocilib::core::Check(), FromString(), and OCI_TimestampCreate().

Member Function Documentation

◆ SysTimestamp()

Timestamp ocilib::Timestamp::SysTimestamp ( TimestampType  type = NoTimeZone)
inlinestatic

return the current system timestamp

Parameters
type- Timestamp type to create

Definition at line 281 of file Timestamp.hpp.

References ocilib::core::Check(), and OCI_TimestampSysTimestamp().

◆ GetType()

Timestamp::TimestampType ocilib::Timestamp::GetType ( ) const
inline

Return the type of the given timestamp object.

Definition at line 74 of file Timestamp.hpp.

References ocilib::core::Check(), and OCI_TimestampGetType().

Referenced by Clone(), GetTimeZone(), and SetTimeZone().

◆ Convert()

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 84 of file Timestamp.hpp.

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

◆ IsValid()

bool ocilib::Timestamp::IsValid ( ) const
inline

Check if the given timestamp is valid.

Definition at line 89 of file Timestamp.hpp.

References ocilib::core::Check(), and OCI_TimestampCheck().

◆ GetYear()

int ocilib::Timestamp::GetYear ( ) const
inline

Return the timestamp year value.

Definition at line 94 of file Timestamp.hpp.

References GetDate().

◆ SetYear()

void ocilib::Timestamp::SetYear ( int  value)
inline

Set the timestamp year value.

Definition at line 103 of file Timestamp.hpp.

References GetDate(), and SetDate().

◆ GetMonth()

int ocilib::Timestamp::GetMonth ( ) const
inline

Return the timestamp month value.

Definition at line 111 of file Timestamp.hpp.

References GetDate().

◆ SetMonth()

void ocilib::Timestamp::SetMonth ( int  value)
inline

Set the timestamp month value.

Definition at line 120 of file Timestamp.hpp.

References GetDate(), and SetDate().

◆ GetDay()

int ocilib::Timestamp::GetDay ( ) const
inline

Return the timestamp day value.

Definition at line 128 of file Timestamp.hpp.

References GetDate().

◆ SetDay()

void ocilib::Timestamp::SetDay ( int  value)
inline

Set the timestamp day value.

Definition at line 137 of file Timestamp.hpp.

References GetDate(), and SetDate().

◆ GetHours()

int ocilib::Timestamp::GetHours ( ) const
inline

Return the timestamp hours value.

Definition at line 145 of file Timestamp.hpp.

References GetTime().

◆ SetHours()

void ocilib::Timestamp::SetHours ( int  value)
inline

Set the timestamp hours value.

Definition at line 154 of file Timestamp.hpp.

References GetTime(), and SetTime().

◆ GetMinutes()

int ocilib::Timestamp::GetMinutes ( ) const
inline

Return the timestamp minutes value.

Definition at line 162 of file Timestamp.hpp.

References GetTime().

◆ SetMinutes()

void ocilib::Timestamp::SetMinutes ( int  value)
inline

Set the timestamp minutes value.

Definition at line 171 of file Timestamp.hpp.

References GetTime(), and SetTime().

◆ GetSeconds()

int ocilib::Timestamp::GetSeconds ( ) const
inline

Return the timestamp seconds value.

Definition at line 179 of file Timestamp.hpp.

References GetTime().

◆ SetSeconds()

void ocilib::Timestamp::SetSeconds ( int  value)
inline

Set the timestamp seconds value.

Definition at line 188 of file Timestamp.hpp.

References GetTime(), and SetTime().

◆ GetMilliSeconds()

int ocilib::Timestamp::GetMilliSeconds ( ) const
inline

Return the timestamp seconds value.

Definition at line 196 of file Timestamp.hpp.

References GetTime().

◆ SetMilliSeconds()

void ocilib::Timestamp::SetMilliSeconds ( int  value)
inline

Set the timestamp milliseconds value.

Definition at line 205 of file Timestamp.hpp.

References GetTime(), and SetTime().

◆ GetDate()

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 213 of file Timestamp.hpp.

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

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

◆ GetTime()

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 218 of file Timestamp.hpp.

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

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

◆ SetDate()

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 228 of file Timestamp.hpp.

References GetDateTime(), and SetDateTime().

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

◆ SetTime()

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 236 of file Timestamp.hpp.

References GetDateTime(), and SetDateTime().

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

◆ GetDateTime()

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 223 of file Timestamp.hpp.

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

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

◆ SetDateTime()

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 79 of file Timestamp.hpp.

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

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

◆ GetTimeZone()

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 255 of file Timestamp.hpp.

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

◆ SetTimeZone()

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 244 of file Timestamp.hpp.

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

◆ GetTimeZoneOffset()

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 271 of file Timestamp.hpp.

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

◆ Substract()

void ocilib::Timestamp::Substract ( const Timestamp lsh,
const Timestamp rsh,
Interval result 
)
inlinestatic

Subtract the given two timestamp and store the result into the given Interval.

Parameters
lsh- Timestamp value
rsh- Timestamp to subtract
result- result difference
Note
the Interval object type must match the type of range resulting from the timestamp difference

Definition at line 276 of file Timestamp.hpp.

References ocilib::core::Check(), and OCI_TimestampSubtract().

◆ FromString()

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 290 of file Timestamp.hpp.

References ocilib::core::Check(), ocilib::FormatTimestamp, ocilib::Environment::GetFormat(), and OCI_TimestampFromText().

Referenced by Timestamp().

◆ ToString() [1/2]

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

Convert the timestamp value to a string using the given format and precision.

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 295 of file Timestamp.hpp.

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

◆ ToString() [2/2]

ostring ocilib::Timestamp::ToString ( ) const
inlineoverridevirtual

Convert the timestamp value to a string using default date format and no precision.

Implements ocilib::core::Streamable.

Definition at line 311 of file Timestamp.hpp.

References ocilib::FormatTimestamp, ocilib::Environment::GetFormat(), and ToString().

Referenced by ToString().

◆ Clone()

Timestamp ocilib::Timestamp::Clone ( ) const
inline

Clone the current instance to a new one performing deep copy.

Definition at line 60 of file Timestamp.hpp.

References ocilib::core::Check(), GetType(), and OCI_TimestampAssign().

Referenced by operator+(), operator++(), operator-(), and operator--().

◆ operator++() [1/2]

Timestamp & ocilib::Timestamp::operator++ ( )
inline

Increment the timestamp by 1 day.

Definition at line 316 of file Timestamp.hpp.

◆ operator++() [2/2]

Timestamp ocilib::Timestamp::operator++ ( int  )
inline

Increment the timestamp by 1 day.

Definition at line 321 of file Timestamp.hpp.

References Clone().

◆ operator--() [1/2]

Timestamp & ocilib::Timestamp::operator-- ( )
inline

Decrement the Timestamp by 1 day.

Definition at line 330 of file Timestamp.hpp.

◆ operator--() [2/2]

Timestamp ocilib::Timestamp::operator-- ( int  )
inline

Decrement the Timestamp by 1 day.

Definition at line 335 of file Timestamp.hpp.

References Clone().

◆ operator+() [1/2]

Timestamp ocilib::Timestamp::operator+ ( int  value) const
inline

Return a new Timestamp holding the current Timestamp value incremented by the given number of days.

Definition at line 344 of file Timestamp.hpp.

References Clone(), ocilib::Interval::DaySecond, and ocilib::Interval::SetDay().

◆ operator-() [1/3]

Timestamp ocilib::Timestamp::operator- ( int  value) const
inline

Return a new Timestamp holding the current Timestamp value decremented by the given number of days.

Definition at line 352 of file Timestamp.hpp.

References Clone(), ocilib::Interval::DaySecond, and ocilib::Interval::SetDay().

◆ operator-() [2/3]

Interval ocilib::Timestamp::operator- ( const Timestamp other)
inline

Return an interval storing the difference between the current timestamp and the given one.

Definition at line 360 of file Timestamp.hpp.

References ocilib::core::Check(), ocilib::Interval::DaySecond, and OCI_TimestampSubtract().

◆ operator+=() [1/2]

Timestamp & ocilib::Timestamp::operator+= ( int  value)
inline

Increment the Timestamp by the given number of days.

Definition at line 391 of file Timestamp.hpp.

References ocilib::Interval::DaySecond, and ocilib::Interval::SetDay().

◆ operator-=() [1/2]

Timestamp & ocilib::Timestamp::operator-= ( int  value)
inline

Decrement the Timestamp by the given number of days.

Definition at line 398 of file Timestamp.hpp.

References ocilib::Interval::DaySecond, and ocilib::Interval::SetDay().

◆ operator+() [2/2]

Timestamp ocilib::Timestamp::operator+ ( const Interval other) const
inline

Return a new Timestamp holding the sum of the current Timestamp value and the given Interval value.

Definition at line 367 of file Timestamp.hpp.

References Clone().

◆ operator-() [3/3]

Timestamp ocilib::Timestamp::operator- ( const Interval other) const
inline

Return a new Timestamp holding the difference of the current Timestamp value and the given Interval value.

Definition at line 373 of file Timestamp.hpp.

References Clone().

◆ operator+=() [2/2]

Timestamp & ocilib::Timestamp::operator+= ( const Interval other)
inline

Increment the current Value with the given Interval value.

Definition at line 379 of file Timestamp.hpp.

References ocilib::core::Check(), and OCI_TimestampIntervalAdd().

◆ operator-=() [2/2]

Timestamp & ocilib::Timestamp::operator-= ( const Interval other)
inline

Decrement the current Value with the given Interval value.

Definition at line 385 of file Timestamp.hpp.

References ocilib::core::Check(), and OCI_TimestampIntervalSub().

◆ operator==()

bool ocilib::Timestamp::operator== ( const Timestamp other) const
inline

Indicates if the current Timestamp value is equal to the given Timestamp value.

Definition at line 405 of file Timestamp.hpp.

◆ operator!=()

bool ocilib::Timestamp::operator!= ( const Timestamp other) const
inline

Indicates if the current Timestamp value is not equal the given Timestamp value.

Definition at line 410 of file Timestamp.hpp.

◆ operator>()

bool ocilib::Timestamp::operator> ( const Timestamp other) const
inline

Indicates if the current Timestamp value is superior to the given Timestamp value.

Definition at line 415 of file Timestamp.hpp.

◆ operator<()

bool ocilib::Timestamp::operator< ( const Timestamp other) const
inline

Indicates if the current Timestamp value is inferior to the given Timestamp value.

Definition at line 420 of file Timestamp.hpp.

◆ operator>=()

bool ocilib::Timestamp::operator>= ( const Timestamp other) const
inline

Indicates if the current Timestamp value is superior or equal to the given Timestamp value.

Definition at line 425 of file Timestamp.hpp.

◆ operator<=()

bool ocilib::Timestamp::operator<= ( const Timestamp other) const
inline

Indicates if the current Timestamp value is inferior or equal to the given Timestamp value.

Definition at line 432 of file Timestamp.hpp.