Skip to content
Snippets Groups Projects
Commit 84b58152 authored by Rene Redler's avatar Rene Redler
Browse files

Update of mtime

commit fc0bedaffe495d9d5e056016a4865164c13c7e91
Author: Luis Kornblueh <luis.kornblueh@zmaw.de>
Date:   Mon Mar 23 16:41:46 2015 +0100

    Removed debug printfs in mtime_timedelta.c.

commit 2ea1e2790e063df94b3cc2d84947f3f27f6a78c7
Merge: 7bd7bae 8a30b0e
Author: Luis Kornblueh <luis.kornblueh@zmaw.de>
Date:   Mon Mar 23 14:08:57 2015 +0100

    Handling of time spans of more than a month with timedelta division.

commit 7bd7bae69984e7f52087844c1f440e6c60980bf4
Author: Luis Kornblueh <luis.kornblueh@zmaw.de>
Date:   Mon Mar 23 14:07:13 2015 +0100

    Handling of time spans of more than a month with timedelta division.

commit 8a30b0efa162b529136158b8901de4702c5509fa
Author: Luis Kornblueh <luis.kornblueh@zmaw.de>
Date:   Mon Mar 23 11:24:34 2015 +0100

    Missed hours in divide hotfix during vacation.
parent ac34bf2d
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@ struct _timedelta
/* Used only for storing division of two time-delta results. */
struct _divisionquotienttimedelta
struct _divisionquotienttimespan
{
int64_t quotient;
int64_t remainder_in_ms;
......@@ -82,8 +82,11 @@ struct _timedelta*
julianDeltaToTimeDelta(struct _juliandelta* jd, struct _datetime *dt, struct _timedelta* td_return);
/*! \endcond */
struct _divisionquotienttimedelta*
divideTimeDeltaInSeconds(struct _timedelta* dividend, struct _timedelta* divisor, struct _divisionquotienttimedelta* quo_ret);
struct _divisionquotienttimespan*
divideTimeDeltaInSeconds(struct _timedelta* dividend, struct _timedelta* divisor, struct _divisionquotienttimespan* quo_ret);
struct _divisionquotienttimespan*
divideDatetimeDifferenceInSeconds(struct _datetime* dt1, struct _datetime* dt2, struct _timedelta* divisor, struct _divisionquotienttimespan* quo_ret);
struct _timedelta*
getTimeDeltaFromDate(struct _date*, struct _date*, struct _timedelta*);
......
......@@ -1067,16 +1067,24 @@ else
/*! \endcond */
struct _divisionquotienttimedelta*
divideTimeDeltaInSeconds(struct _timedelta* dividend, struct _timedelta* divisor, struct _divisionquotienttimedelta* quo_ret)
struct _divisionquotienttimespan*
divideTimeDeltaInSeconds(struct _timedelta* dividend, struct _timedelta* divisor, struct _divisionquotienttimespan* quo_ret)
{
if ((dividend != NULL) && (divisor != NULL) && (quo_ret != NULL))
{
if ((dividend->year == 0) && (dividend->month == 0) && (divisor->year == 0) && (divisor->month == 0))
{
intmax_t numerator = (intmax_t) (((int64_t) dividend->day * 86400 + dividend->minute * 60 + dividend->second) * 1000 + dividend->ms);
intmax_t denominator = (intmax_t) (((int64_t) divisor->day * 86400 + divisor->minute * 60 + divisor->second ) * 1000 + divisor->ms);
intmax_t numerator = (intmax_t) (((int64_t) dividend->day * 86400 +
dividend->hour * 3600 +
dividend->minute * 60 +
dividend->second) * 1000 +
dividend->ms);
intmax_t denominator = (intmax_t) (((int64_t) divisor->day * 86400 +
divisor->hour * 3600 +
divisor->minute * 60 +
divisor->second ) * 1000 +
divisor->ms);
if (denominator == 0) /* Division by zero is illegal. */
return NULL;
......@@ -1088,9 +1096,59 @@ divideTimeDeltaInSeconds(struct _timedelta* dividend, struct _timedelta* divisor
return quo_ret;
}
else /* Only seconds supported */
return NULL;
}
else
return NULL;
}
/**
* @brief division by an interval given in of seconds.
*
* @param refdt
* Reference date (a pointer to struct _datetime).
* @param dt
* A pointer to struct _datetime.
* @param intvlsec
* Interval given in seconds.
*
* @return result of division. NULL indicates error.
*/
struct _divisionquotienttimespan*
divideDatetimeDifferenceInSeconds(struct _datetime* dt1, struct _datetime* dt2, struct _timedelta* divisor, struct _divisionquotienttimespan* quo_ret)
{
if ((dt1 != NULL) && (dt2 != NULL) && (divisor != NULL) && (quo_ret != NULL))
{
if ((divisor->year == 0) && (divisor->month == 0))
{
return NULL;
struct _julianday* jd1 = newJulianDay(0, 0);
if (jd1 != NULL) jd1 = date2julian(dt1, jd1);
struct _julianday* jd2 = newJulianDay(0, 0);
if (jd2 != NULL) jd2 = date2julian(dt2, jd2);
intmax_t denominator = (intmax_t) (((int64_t) divisor->day * 86400 + divisor->hour * 3600 +divisor->minute * 60 + divisor->second ) * 1000 + divisor->ms);
if (denominator == 0) /* Division by zero is illegal. */
return NULL;
struct _juliandelta* jd = newJulianDelta('+', 0, 0);
jd = substractJulianDay(jd1, jd2, jd);
intmax_t numerator = (intmax_t) (jd->day * 86400000 + jd->ms);
imaxdiv_t div = imaxdiv(numerator, denominator);
quo_ret->quotient = (int64_t) div.quot;
quo_ret->remainder_in_ms = (int64_t) div.rem;
if (jd1 != NULL) deallocateJulianDay(jd1);
if (jd2 != NULL) deallocateJulianDay(jd2);
if (jd != NULL) deallocateJulianDelta(jd);
return quo_ret;
}
else
return NULL;
}
else
return NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment