Skip to content
Snippets Groups Projects

Fix timedelta scalar multiplication

Merged Sergey Kosukhin requested to merge fix-timedelta-mult into master
+ 8
6
@@ -1691,19 +1691,21 @@ elementwiseScalarMultiplyTimeDelta(struct _timedelta* base_td, int64_t lambda, s
lambda = (int64_t)(llabs(lambda));
/* Multiply each element by scalar. */
int64_t ms_temp = lambda * base_td->ms;
int64_t ms_temp = scaled_td->ms + lambda * base_td->ms;
scaled_td->ms = (int)(ms_temp % NO_OF_MS_IN_A_SECOND);
int64_t s_temp = lambda*base_td->second + ms_temp / NO_OF_MS_IN_A_SECOND;
int64_t s_temp = scaled_td->second + lambda * base_td->second
+ ms_temp / NO_OF_MS_IN_A_SECOND;
scaled_td->second = (int)(s_temp % 60);
int64_t m_temp = lambda*base_td->minute + s_temp / 60;
int64_t m_temp = scaled_td->minute + lambda * base_td->minute
+ s_temp / 60;
scaled_td->minute = (int)(m_temp % 60);
int64_t h_temp = lambda*base_td->hour + m_temp / 60;
scaled_td->hour = (int)(h_temp % NO_OF_HOURS_IN_A_DAY);
scaled_td->hour += (int)(lambda * base_td->hour + m_temp / 60);
/* Scalar multiplication must not give a value in excess of 24 hours. */
if ( h_temp >= NO_OF_HOURS_IN_A_DAY )
if ( scaled_td->hour >= NO_OF_HOURS_IN_A_DAY )
{
/* ERROR: Return on NULL. */
return NULL;
Loading