Add no-deprecated to warnings due to dynamic exceptions.
[anna.git] / include / anna / dbms / TimeStamp.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_dbms_TimeStamp_hpp
10 #define anna_dbms_TimeStamp_hpp
11
12 #include <anna/dbms/Date.hpp>
13
14 namespace anna {
15
16 namespace dbms {
17
18 /**
19    Tipo de datos que permite trabajar con el tipo de dato 'TimeStamp' de un gestor de base de
20    datos generico.
21
22    El tipo de dato TimeStamp contiene la información suficiente para representar una fecha
23    incluyendo la hora del día.
24 */
25 class TimeStamp : public Date {
26 public:
27   /**
28      Constructor.
29      \param isNulleable Indica si el dato puede tomar valores nulos.
30      \param format Formato usado para interpretar los datos de esta fecha, en los metodos Date::getCStringValue y
31      Date::setValue (const char*) y Date::setValue (const std::string&). Sigue la especificacion:
32
33      \code
34       %a     Replaced by the localeâs abbreviated weekday name. [ tm_wday]
35
36       %A     Replaced by the localeâs full weekday name. [ tm_wday]
37
38       %b     Replaced by the localeâs abbreviated month name. [ tm_mon]
39
40       %B     Replaced by the localeâs full month name. [ tm_mon]
41
42       %c     Replaced  by  the  locale's  appropriate date and time representation.  (See the Base Definitions volume of
43              IEEE Std 1003.1-2001, <time.h>.)
44
45       %C     Replaced by the year divided by 100 and truncated to an integer, as a decimal number [00,99]. [ tm_year]
46
47       %d     Replaced by the day of the month as a decimal number [01,31]. [ tm_mday]
48
49       %D     Equivalent to %m / %d / %y . [ tm_mon, tm_mday, tm_year]
50
51       %e     Replaced by the day of the month as a decimal number [1,31]; a single digit  is  preceded  by  a  space.  [
52              tm_mday]
53
54       %F     Equivalent to %Y - %m - %d (the ISO 8601:2000 standard date format). [ tm_year, tm_mon, tm_mday]
55
56       %g     Replaced  by  the  last 2 digits of the week-based year (see below) as a decimal number [00,99]. [ tm_year,
57              tm_wday, tm_yday]
58
59       %G     Replaced by the week-based year (see below) as a decimal number (for example, 1977).  [  tm_year,  tm_wday,
60              tm_yday]
61
62       %h     Equivalent to %b . [ tm_mon]
63
64       %H     Replaced by the hour (24-hour clock) as a decimal number [00,23].  [ tm_hour]
65
66       %I     Replaced by the hour (12-hour clock) as a decimal number [01,12].  [ tm_hour]
67
68       %j     Replaced by the day of the year as a decimal number [001,366]. [ tm_yday]
69
70       %m     Replaced by the month as a decimal number [01,12]. [ tm_mon]
71
72       %M     Replaced by the minute as a decimal number [00,59]. [ tm_min]
73
74       %n     Replaced by a <newline>.
75
76       %p     Replaced by the locale's equivalent of either a.m. or p.m. [ tm_hour]
77
78       %r     Replaced  by the time in a.m. and p.m. notation;    in the POSIX locale this shall be equivalent to %I : %M
79              : %S %p .  [ tm_hour, tm_min, tm_sec]
80
81       %R     Replaced by the time in 24-hour notation ( %H : %M ).  [ tm_hour, tm_min]
82
83       %S     Replaced by the second as a decimal number [00,60]. [ tm_sec]
84
85       %t     Replaced by a <tab>.
86
87       %T     Replaced by the time ( %H : %M : %S ). [ tm_hour, tm_min, tm_sec]
88
89       %u     Replaced by the weekday as a decimal number [1,7], with 1 representing Monday. [ tm_wday]
90
91       %U     Replaced by the week number of the year as a decimal number [00,53].  The first Sunday of  January  is  the
92              first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
93
94       %V     Replaced  by the week number of the year (Monday as the first day of the week) as a decimal number [01,53].
95              If the week containing 1 January has four or more days in the new year, then it is considered week 1.  Oth-
96              erwise,  it  is  the  last week of the previous year, and the next week is week 1. Both January 4th and the
97              first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday]
98
99       %w     Replaced by the weekday as a decimal number [0,6], with 0 representing Sunday. [ tm_wday]
100
101       %W     Replaced by the week number of the year as a decimal number [00,53].  The first Monday of  January  is  the
102              first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
103
104       %x     Replaced   by   the  locale's  appropriate  date  representation.  (See  the  Base  Definitions  volume  of
105              IEEE Std 1003.1-2001, <time.h>.)
106
107       %X     Replaced  by  the  locale's  appropriate  time  representation.  (See  the  Base  Definitions   volume   of
108              IEEE Std 1003.1-2001, <time.h>.)
109
110       %y     Replaced by the last two digits of the year as a decimal number [00,99].  [ tm_year]
111
112       %Y     Replaced by the year as a decimal number (for example, 1997). [ tm_year]
113
114       %z     Replaced  by  the offset from UTC in the ISO 8601:2000 standard format ( +hhmm or -hhmm ), or by no charac-
115              ters if no timezone is determinable. For example, "-0430" means 4 hours 30  minutes  behind  UTC  (west  of
116              Greenwich).    If tm_isdst is zero, the standard time offset is used. If tm_isdst is greater than zero, the
117              daylight savings time offset is used. If tm_isdst is negative, no characters are returned.  [ tm_isdst]
118
119       %Z     Replaced by the timezone name or abbreviation, or  by  no  bytes  if  no  timezone  information  exists.  [
120              tm_isdst]
121
122       %%     Replaced by % .
123      \endcode
124
125      Para obtener más informacion sobre la espeficacion de formato \em man \em strftime (p.e.).
126
127      Para poder obtener la parte fraccionaria en la salida del metodo #getCStringValue hay que indicar el literal \em %%d. Por ejemplo:
128
129      \code
130      TimeStamp oneTime (false, "%T.%%d")
131      \endcode
132    */
133   explicit TimeStamp(const bool isNulleable = false, const char* format = NULL)  :
134     Date(Data::Type::TimeStamp, isNulleable, format),
135     a_fractionalSecond(0)
136   {;}
137
138   /**
139    * Devuelve la parte fraccionaria de los segundos asociados a este objeto.
140    * \return La parte fraccionaria de los segundos asociados a este objeto.
141    */
142   int getFractionalSecond() const throw() { return a_fractionalSecond; }
143
144   /**
145    * Establece la parte fraccionaria de los segundos de este objeto.
146    * \param fsec Parte fraccionaria de los segundos.
147    */
148   void setFractionalSecond(const int fsec) throw() { a_fractionalSecond = fsec; }
149
150   /**
151    * Interpreta el contenido de la fecha y lo transfiere al buffer.
152    * \return El buffer que contiene esta fecha interpretada con el formato indicado en el contructor.
153    *  \warning El resultado sera NULL en caso de no poder interpretar correctamente la fecha.
154    */
155   virtual const char* getCStringValue() const throw();
156
157   /**
158      Operador de copia.
159      \param timeStamp Fecha de la que copiar.
160      \return La instancia de esta fecha.
161      \warning Solo copia el contenido de la fecha recibida, no cambia el formato de interpretacion de la fecha origen.
162   */
163   TimeStamp& operator = (const TimeStamp& timeStamp) throw(RuntimeException) {
164     Date::operator= (timeStamp);
165     a_fractionalSecond = timeStamp.a_fractionalSecond;
166     return *this;
167   }
168
169   /**
170      Operador de copia.
171      \param date Fecha de la que copiar.
172      \return La instancia de esta fecha.
173      \warning Solo copia el contenido de la fecha recibida, no cambia el formato de interpretacion de la fecha origen.
174   */
175   TimeStamp& operator = (const Date& date) throw(RuntimeException) { Date::operator= (date); a_fractionalSecond = 0; return *this; }
176
177 private:
178   char a_anotherBuffer [MaxDateSize + 1];
179   int a_fractionalSecond;
180
181   void do_clear() throw() { a_fractionalSecond = 0; a_anotherBuffer [0] = 0; }
182 };
183
184 }
185 }
186
187 #endif
188