@@ -57,19 +57,19 @@ namespace Firebird {
57
57
class NoThrowTimeStamp
58
58
{
59
59
public:
60
- static const ISC_DATE MIN_DATE = -678575 ; // 01.01.0001
61
- static const ISC_DATE MAX_DATE = 2973483 ; // 31.12.9999
62
- static const ISC_DATE UNIX_DATE = 40587 ; // 01.01.1970
60
+ static constexpr ISC_DATE MIN_DATE = -678575 ; // 01.01.0001
61
+ static constexpr ISC_DATE MAX_DATE = 2973483 ; // 31.12.9999
62
+ static constexpr ISC_DATE UNIX_DATE = 40587 ; // 01.01.1970
63
63
64
- static const SINT64 SECONDS_PER_DAY = 24 * 60 * 60 ;
65
- static const SINT64 ISC_TICKS_PER_DAY = SECONDS_PER_DAY * ISC_TIME_SECONDS_PRECISION;
64
+ static constexpr SINT64 SECONDS_PER_DAY = 24 * 60 * 60 ;
65
+ static constexpr SINT64 ISC_TICKS_PER_DAY = SECONDS_PER_DAY * ISC_TIME_SECONDS_PRECISION;
66
66
67
67
static const ISC_TIMESTAMP MIN_TIMESTAMP;
68
68
static const ISC_TIMESTAMP MAX_TIMESTAMP;
69
69
70
70
private:
71
- static const ISC_DATE BAD_DATE = MAX_SLONG;
72
- static const ISC_TIME BAD_TIME = MAX_ULONG;
71
+ static constexpr ISC_DATE BAD_DATE = MAX_SLONG;
72
+ static constexpr ISC_TIME BAD_TIME = MAX_ULONG;
73
73
74
74
public:
75
75
// Number of the first day of UNIX epoch in GDS counting
@@ -78,39 +78,39 @@ class NoThrowTimeStamp
78
78
static const ISC_TIME POW_10_TABLE[];
79
79
80
80
// Constructors
81
- NoThrowTimeStamp ()
81
+ NoThrowTimeStamp () noexcept
82
82
{
83
83
invalidate ();
84
84
}
85
85
86
- NoThrowTimeStamp (const ISC_TIMESTAMP& from)
86
+ NoThrowTimeStamp (const ISC_TIMESTAMP& from) noexcept
87
87
: mValue (from)
88
88
{}
89
89
90
- NoThrowTimeStamp (ISC_DATE date, ISC_TIME time)
90
+ NoThrowTimeStamp (ISC_DATE date, ISC_TIME time) noexcept
91
91
{
92
92
mValue .timestamp_date = date;
93
93
mValue .timestamp_time = time;
94
94
}
95
95
96
- explicit NoThrowTimeStamp (const struct tm & times, int fractions = 0 )
96
+ explicit NoThrowTimeStamp (const struct tm & times, int fractions = 0 ) noexcept
97
97
{
98
98
encode (×, fractions);
99
99
}
100
100
101
- bool isValid () const
101
+ bool isValid () const noexcept
102
102
{
103
103
return isValidTimeStamp (mValue );
104
104
}
105
105
106
106
// Check if timestamp contains a non-existing value
107
- bool isEmpty () const
107
+ bool isEmpty () const noexcept
108
108
{
109
109
return (mValue .timestamp_date == BAD_DATE && mValue .timestamp_time == BAD_TIME);
110
110
}
111
111
112
112
// Set value of timestamp to a non-existing value
113
- void invalidate ()
113
+ void invalidate () noexcept
114
114
{
115
115
mValue .timestamp_date = BAD_DATE;
116
116
mValue .timestamp_time = BAD_TIME;
@@ -126,32 +126,32 @@ class NoThrowTimeStamp
126
126
}
127
127
128
128
// Encode timestamp from UNIX datetime structure
129
- void encode (const struct tm * times, int fractions = 0 );
129
+ void encode (const struct tm * times, int fractions = 0 ) noexcept ;
130
130
131
131
// Decode timestamp into UNIX datetime structure
132
- void decode (struct tm * times, int * fractions = NULL ) const ;
132
+ void decode (struct tm * times, int * fractions = NULL ) const noexcept ;
133
133
134
134
// Write access to timestamp structure we wrap
135
- ISC_TIMESTAMP& value () { return mValue ; }
135
+ ISC_TIMESTAMP& value () noexcept { return mValue ; }
136
136
137
137
// Read access to timestamp structure we wrap
138
- const ISC_TIMESTAMP& value () const { return mValue ; }
138
+ const ISC_TIMESTAMP& value () const noexcept { return mValue ; }
139
139
140
140
// Return current timestamp value
141
141
static NoThrowTimeStamp getCurrentTimeStamp (const char ** error) noexcept ;
142
142
143
143
// Validation routines
144
- static bool isValidDate (const ISC_DATE ndate)
144
+ static constexpr bool isValidDate (const ISC_DATE ndate) noexcept
145
145
{
146
146
return (ndate >= MIN_DATE && ndate <= MAX_DATE);
147
147
}
148
148
149
- static bool isValidTime (const ISC_TIME ntime)
149
+ static constexpr bool isValidTime (const ISC_TIME ntime) noexcept
150
150
{
151
151
return (ntime < 24 * 3600 * ISC_TIME_SECONDS_PRECISION);
152
152
}
153
153
154
- static bool isValidTimeStamp (const ISC_TIMESTAMP ts)
154
+ static constexpr bool isValidTimeStamp (const ISC_TIMESTAMP ts) noexcept
155
155
{
156
156
return (isValidDate (ts.timestamp_date ) && isValidTime (ts.timestamp_time ));
157
157
}
@@ -165,25 +165,24 @@ class NoThrowTimeStamp
165
165
static void decode_time (ISC_TIME ntime, int * hours, int * minutes, int * seconds, int * fractions = NULL ) noexcept ;
166
166
static void decode_timestamp (const ISC_TIMESTAMP ntimestamp, struct tm * times, int * fractions = NULL ) noexcept ;
167
167
168
- static void add10msec (ISC_TIMESTAMP* v, SINT64 msec, SINT64 multiplier);
169
- static void round_time (ISC_TIME& ntime, const int precision);
168
+ static void add10msec (ISC_TIMESTAMP* v, SINT64 msec, SINT64 multiplier) noexcept ;
169
+ static void round_time (ISC_TIME& ntime, const int precision) noexcept ;
170
170
171
- static int convertGregorianDateToWeekDate (const struct tm & times);
172
- static int convertGregorianDateToJulianDate (int year, int month, int day);
173
- static void convertJulianDateToGregorianDate (int jdn, int & outYear, int & outMonth, int & outDay);
171
+ static int convertGregorianDateToWeekDate (const struct tm & times) noexcept ;
172
+ static int convertGregorianDateToJulianDate (int year, int month, int day) noexcept ;
173
+ static void convertJulianDateToGregorianDate (int jdn, int & outYear, int & outMonth, int & outDay) noexcept ;
174
174
175
- static inline bool isLeapYear (const int year) noexcept
175
+ static constexpr bool isLeapYear (const int year) noexcept
176
176
{
177
177
return (year % 4 == 0 && year % 100 != 0 ) || (year % 400 == 0 );
178
178
}
179
179
180
- static SINT64 timeStampToTicks (ISC_TIMESTAMP ts)
180
+ static constexpr SINT64 timeStampToTicks (ISC_TIMESTAMP ts) noexcept
181
181
{
182
- const SINT64 ticks = (ts.timestamp_date - MIN_DATE) * ISC_TICKS_PER_DAY + ts.timestamp_time ;
183
- return ticks;
182
+ return (static_cast <SINT64>(ts.timestamp_date ) - MIN_DATE) * ISC_TICKS_PER_DAY + ts.timestamp_time ;
184
183
}
185
184
186
- static ISC_TIMESTAMP ticksToTimeStamp (SINT64 ticks)
185
+ static constexpr ISC_TIMESTAMP ticksToTimeStamp (SINT64 ticks) noexcept
187
186
{
188
187
ISC_TIMESTAMP ts;
189
188
ts.timestamp_date = (ticks / ISC_TICKS_PER_DAY) + MIN_DATE;
0 commit comments