ANNA Suite  2020b
Multipurpose development suite for Telco applications
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
anna::dbms::Date Class Reference

#include <Date.hpp>

Inheritance diagram for anna::dbms::Date:
Inheritance graph
[legend]
Collaboration diagram for anna::dbms::Date:
Collaboration graph
[legend]

Public Member Functions

 Date (const bool isNulleable=false, const char *format=NULL)
 
 Date (const Date &other)
 
virtual ~Date ()
 
const tm & getValue () const
 
tm & getValue ()
 
virtual const char * getCStringValue () const
 
Second getSecondValue () const
 
const char * getFormat () const
 
int getYear () const
 
int getMonth () const
 
int getDay () const
 
int getHour () const
 
int getMinute () const
 
int getSecond () const
 
void setYear (const int year) noexcept(false)
 
void setMonth (const int month) noexcept(false)
 
void setDay (const int day) noexcept(false)
 
void setHour (const int hour) noexcept(false)
 
void setMinute (const int minute) noexcept(false)
 
void setSecond (const int second) noexcept(false)
 
void setValue (const char *str) noexcept(false)
 
void setValue (const std::string &str) noexcept(false)
 
void setValue (const Second &second) noexcept(false)
 
Dateoperator= (const Date &date) noexcept(false)
 
virtual std::string asString () const
 
- Public Member Functions inherited from anna::dbms::Data
int getMaxSize () const
 
Type::_v getType () const
 
void * getBuffer ()
 
bool isNull () const
 
bool isNulleable () const
 
void setNull (const bool isNull)
 
void clear ()
 

Static Public Attributes

static const int MaxDateSize = 48
 

Protected Member Functions

 Date (const Type::_v type, const bool isNulleable, const char *format)
 
- Protected Member Functions inherited from anna::dbms::Data
 Data (const Type::_v type, const int maxSize, const bool isNulleable)
 
 Data (const Data &other)
 
void setBuffer (void *buffer)
 

Protected Attributes

char * a_format
 
tm a_value
 
char a_buffer [MaxDateSize+1]
 

Detailed Description

Tipo de datos que permite trabajar con el tipo de dato 'Date' de un gestor de base de datos generico.

Dependiendo el gestor de base de datos usado el tipo date puede contener informacion que incluya la hora del día, en Oracle (tm) la incluye, mientras que en mysql, por ejemplo, no la incluye.

Internamente trabaja con una estructura de tipo 'tm' que habitualmente tendrá los campos:

struct tm {
int tm_sec; // Seconds. [0-60] (1 leap second)
int tm_min; // Minutes. [0-59]
int tm_hour; // Hours. [0-23]
int tm_mday; // Day. [1-31]
int tm_mon; // Month. [0-11]
int tm_year; // Year - 1900.
int tm_wday; // Day of week. [0-6]
int tm_yday; // Days in year.[0-365]
int tm_isdst; // DST. [-1/0/1]
};

Constructor & Destructor Documentation

◆ Date() [1/3]

anna::dbms::Date::Date ( const bool  isNulleable = false,
const char *  format = NULL 
)
explicit

Constructor.

Parameters
isNulleableIndica si el dato puede tomar valores nulos.
formatFormato usado para interpretar los datos de esta fecha, en los metodos Date::getCStringValue y Date::setValue (const char*) y Date::setValue (const std::string&). Sigue la especificacion:
%a Replaced by the localeâs abbreviated weekday name. [ tm_wday]
%A Replaced by the localeâs full weekday name. [ tm_wday]
%b Replaced by the localeâs abbreviated month name. [ tm_mon]
%B Replaced by the localeâs full month name. [ tm_mon]
%c Replaced by the localeâs appropriate date and time representation. (See the Base Definitions volume of
IEEE Std 1003.1-2001, <time.h>.)
%C Replaced by the year divided by 100 and truncated to an integer, as a decimal number [00,99]. [ tm_year]
%d Replaced by the day of the month as a decimal number [01,31]. [ tm_mday]
%D Equivalent to %m / %d / %y . [ tm_mon, tm_mday, tm_year]
%e Replaced by the day of the month as a decimal number [1,31]; a single digit is preceded by a space. [
tm_mday]
%F Equivalent to %Y - %m - %d (the ISO 8601:2000 standard date format). [ tm_year, tm_mon, tm_mday]
%g Replaced by the last 2 digits of the week-based year (see below) as a decimal number [00,99]. [ tm_year,
tm_wday, tm_yday]
%G Replaced by the week-based year (see below) as a decimal number (for example, 1977). [ tm_year, tm_wday,
tm_yday]
%h Equivalent to %b . [ tm_mon]
%H Replaced by the hour (24-hour clock) as a decimal number [00,23]. [ tm_hour]
%I Replaced by the hour (12-hour clock) as a decimal number [01,12]. [ tm_hour]
%j Replaced by the day of the year as a decimal number [001,366]. [ tm_yday]
%m Replaced by the month as a decimal number [01,12]. [ tm_mon]
%M Replaced by the minute as a decimal number [00,59]. [ tm_min]
%n Replaced by a <newline>.
%p Replaced by the localeâs equivalent of either a.m. or p.m. [ tm_hour]
%r Replaced by the time in a.m. and p.m. notation; in the POSIX locale this shall be equivalent to %I : %M
: %S %p . [ tm_hour, tm_min, tm_sec]
%R Replaced by the time in 24-hour notation ( %H : %M ). [ tm_hour, tm_min]
%S Replaced by the second as a decimal number [00,60]. [ tm_sec]
%t Replaced by a <tab>.
%T Replaced by the time ( %H : %M : %S ). [ tm_hour, tm_min, tm_sec]
%u Replaced by the weekday as a decimal number [1,7], with 1 representing Monday. [ tm_wday]
%U Replaced by the week number of the year as a decimal number [00,53]. The first Sunday of January is the
first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
%V Replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01,53].
If the week containing 1 January has four or more days in the new year, then it is considered week 1. Oth-
erwise, it is the last week of the previous year, and the next week is week 1. Both January 4th and the
first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday]
%w Replaced by the weekday as a decimal number [0,6], with 0 representing Sunday. [ tm_wday]
%W Replaced by the week number of the year as a decimal number [00,53]. The first Monday of January is the
first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
%x Replaced by the localeâs appropriate date representation. (See the Base Definitions volume of
IEEE Std 1003.1-2001, <time.h>.)
%X Replaced by the localeâs appropriate time representation. (See the Base Definitions volume of
IEEE Std 1003.1-2001, <time.h>.)
%y Replaced by the last two digits of the year as a decimal number [00,99]. [ tm_year]
%Y Replaced by the year as a decimal number (for example, 1997). [ tm_year]
%z Replaced by the offset from UTC in the ISO 8601:2000 standard format ( +hhmm or -hhmm ), or by no charac-
ters if no timezone is determinable. For example, "-0430" means 4 hours 30 minutes behind UTC (west of
Greenwich). If tm_isdst is zero, the standard time offset is used. If tm_isdst is greater than zero, the
daylight savings time offset is used. If tm_isdst is negative, no characters are returned. [ tm_isdst]
%Z Replaced by the timezone name or abbreviation, or by no bytes if no timezone information exists. [
tm_isdst]
%% Replaced by % .

Para obtener más informacion sobre la espeficacion de formato man strftime (p.e.).

◆ Date() [2/3]

anna::dbms::Date::Date ( const Date other)

Constructor copia.

Parameters
otherInstancia de la que copiar.

◆ ~Date()

virtual anna::dbms::Date::~Date ( )
virtual

Destructor.

◆ Date() [3/3]

anna::dbms::Date::Date ( const Type::_v  type,
const bool  isNulleable,
const char *  format 
)
explicitprotected

Constructor invocado desde el constructor de TimeStamp.

Parameters
typeSera Data::Type::TimeStamp.
isNulleableIndica si el dato puede tomar valores nulos.
formatFormato usado para representar los datos de esta fecha.

Member Function Documentation

◆ asString()

virtual std::string anna::dbms::Date::asString ( ) const
virtual

Devuelve una cadena con la informacion referente a esta instancia.

Returns
Una cadena con la informacion referente a esta instancia.

Reimplemented from anna::dbms::Data.

◆ getCStringValue()

virtual const char* anna::dbms::Date::getCStringValue ( ) const
virtual

Interpreta el contenido de la fecha y lo transfiere al buffer.

Returns
El buffer que contiene esta fecha interpretada con el formato indicado en el contructor.
Warning
El resultado sera NULL en caso de no poder interpretar correctamente la fecha.

Reimplemented in anna::dbms::TimeStamp.

◆ getDay()

int anna::dbms::Date::getDay ( ) const
inline

Devuelve el dia del mes contenido por esta fecha.

Returns
El dia del mes contenido por esta fecha.
218 { return a_value.tm_mday; }
tm a_value
Definition: Date.hpp:317

◆ getFormat()

const char* anna::dbms::Date::getFormat ( ) const
inline

Devuelve el formato indicado en el constructor de la clase.

Returns
El formato indicado en el constructor de la clase.
200 { return a_format; }
char * a_format
Definition: Date.hpp:316

◆ getHour()

int anna::dbms::Date::getHour ( ) const
inline

Devuelve la hora del dia contenida en la fecha.

Returns
La hora del dia contenida en la fecha.
Warning
Verifique que el tipo 'Date' de su RDBMS es capaz de contener horas, minutos y segundos.
225 { return a_value.tm_hour; }
tm a_value
Definition: Date.hpp:317

◆ getMinute()

int anna::dbms::Date::getMinute ( ) const
inline

Devuelve el minuto de la hora contenida en la fecha.

Returns
El minuto de la hora contenida en la fecha.
Warning
Verifique que el tipo 'Date' de su RDBMS es capaz de contener horas, minutos y segundos.
232 { return a_value.tm_min; }
tm a_value
Definition: Date.hpp:317

◆ getMonth()

int anna::dbms::Date::getMonth ( ) const
inline

Devuelve el mes contenido por esta fecha.

Returns
El mes contenido por esta fecha.
212 { return a_value.tm_mon + 1; }
tm a_value
Definition: Date.hpp:317

◆ getSecond()

int anna::dbms::Date::getSecond ( ) const
inline

Devuelve el segundo de la hora contenida en la fecha.

Returns
El segundo de la hora contenida en la fecha.
Warning
Verifique que el tipo 'Date' de su RDBMS es capaz de contener horas, minutos y segundos.
239 { return a_value.tm_sec; }
tm a_value
Definition: Date.hpp:317

◆ getSecondValue()

Second anna::dbms::Date::getSecondValue ( ) const
inline

Interpreta el contenido de esta fecha como el numero de segundos transcurridos desde el 1 de Enero de 1970. Si el contenido de la columna sociada es nulo este metodo devolvera 0. Si la conversion a segundos no puede ser realizada devolvera -1.

Returns
Interpreta el contenido de esta fecha como el numero de segundos transcurridos desde el 1 de Enero de 1970. Si el contenido de la columna sociada es nulo este metodo devolvera 0. Si la conversion a segundos no puede ser realizada devolvera -1.
194 { return Second((Data::isNull() == true) ? 0 : mktime(&const_cast <Date*>(this)->a_value)); }
bool isNull() const
Definition: Data.hpp:62
tm a_value
Definition: Date.hpp:317
Here is the call graph for this function:

◆ getValue() [1/2]

const tm& anna::dbms::Date::getValue ( ) const
inline

Devuelve el contenido de esta fecha.

Returns
El contenido de esta fecha.
Warning
Si el metodo Data::isNull devolvio true el contenido de la estructura no esta definido.
170 { return a_value; }
tm a_value
Definition: Date.hpp:317

◆ getValue() [2/2]

tm& anna::dbms::Date::getValue ( )
inline

Devuelve el contenido de esta fecha.

Returns
El contenido de esta fecha.
Warning
Si el metodo Data::isNull devolvio true el contenido de la estructura no esta definido.
177 { return a_value; }
tm a_value
Definition: Date.hpp:317
Here is the call graph for this function:

◆ getYear()

int anna::dbms::Date::getYear ( ) const
inline

Devuelve el año contenido por esta fecha.

Returns
El año contenido por esta fecha.
206 { return a_value.tm_year + 1900; }
tm a_value
Definition: Date.hpp:317

◆ operator=()

Date& anna::dbms::Date::operator= ( const Date date)
noexcept

Operador de copia.

Parameters
dateFecha de la que copiar.
Returns
La instancia de esta fecha.
Warning
Solo copia el contenido de la fecha recibida, no cambia el formato de interpretacion de la fecha origen.

◆ setDay()

void anna::dbms::Date::setDay ( const int  day)
inlinenoexcept

Establece el dia del mes de esta fecha.

Parameters
dayDia del mes. Debe estar comprendido entre 1 y 31.
257 { set("Day", a_value.tm_mday, day, 1, 31); }
tm a_value
Definition: Date.hpp:317

◆ setHour()

void anna::dbms::Date::setHour ( const int  hour)
inlinenoexcept

Establece la hora de esta fecha.

Parameters
hourHora del dia. Debe estar comprendida entre 0 y 23.
Warning
Verifique que el tipo 'Date' de su RDBMS es capaz de contener horas, minutos y segundos.
264 { set("Hour", a_value.tm_hour, hour, 0, 23); }
tm a_value
Definition: Date.hpp:317

◆ setMinute()

void anna::dbms::Date::setMinute ( const int  minute)
inlinenoexcept

Establece el minuto de esta fecha.

Parameters
minuteMinuto de la hora del dia. Debe estar comprendida entre 0 y 59.
Warning
Verifique que el tipo 'Date' de su RDBMS es capaz de contener horas, minutos y segundos.
271 { set("Minute", a_value.tm_min, minute, 0, 59); }
tm a_value
Definition: Date.hpp:317

◆ setMonth()

void anna::dbms::Date::setMonth ( const int  month)
inlinenoexcept

Establece mes de esta fecha.

Parameters
monthMes de la fecha. Debe estar comprendido entre 1 y 12.
251 { set("Month", a_value.tm_mon, month - 1, 0, 11); }
tm a_value
Definition: Date.hpp:317

◆ setSecond()

void anna::dbms::Date::setSecond ( const int  second)
inlinenoexcept

Establece el segundo de esta fecha.

Parameters
secondSegungo de la hora del dia. Debe estar comprendida entre 0 y 60.
Warning
Verifique que el tipo 'Date' de su RDBMS es capaz de contener horas, minutos y segundos.
278 { set("Second", a_value.tm_sec, second, 0, 60); }
tm a_value
Definition: Date.hpp:317
Here is the call graph for this function:

◆ setValue() [1/3]

void anna::dbms::Date::setValue ( const char *  str)
noexcept

Interpreta la cadena recibida segun el formato indicado en el constructor y la asigna a esta instancia, pero requiere que al invocar al constructor de esta fecha se indique el formato usado para traducir.

Parameters
strCadena de la que copiar.

◆ setValue() [2/3]

void anna::dbms::Date::setValue ( const std::string &  str)
inlinenoexcept

Interpreta la cadena recibida segun el formato indicado en el constructor y la asigna a esta instancia, pero requiere que al invocar al constructor de esta fecha se indique el formato usado para traducir.

Parameters
strCadena de la que copiar.
292 { setValue(str.c_str()); }
void setValue(const char *str) noexcept(false)
Here is the call graph for this function:

◆ setValue() [3/3]

void anna::dbms::Date::setValue ( const Second second)
noexcept

Establece esta fecha con los segundos transcurridos desde el 1/1/1970.

Parameters
secondNumeros de segundos transcurridos desde el 1 de Enero de 1970.
See also
anna::functions::second

◆ setYear()

void anna::dbms::Date::setYear ( const int  year)
inlinenoexcept

Establece el año de esta fecha

Parameters
yearAño de la fecha. Debe ser mayor de 1900.
245 { set("Year", a_value.tm_year, year - 1900, 0, -1); }
tm a_value
Definition: Date.hpp:317

Member Data Documentation

◆ a_buffer

char anna::dbms::Date::a_buffer[MaxDateSize+1]
protected

◆ a_format

char* anna::dbms::Date::a_format
protected

◆ a_value

tm anna::dbms::Date::a_value
protected

◆ MaxDateSize

const int anna::dbms::Date::MaxDateSize = 48
static

Espacio maximo reservado para representar lo datos de una fecha sobre una cadena.


The documentation for this class was generated from the following file: