mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Remove basically-unused qof date manipulation code better provided by GDate.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15499 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -297,41 +297,6 @@ gboolean date_is_last_mday(struct tm *tm)
|
||||
return(tm->tm_mday == date_get_last_mday(tm));
|
||||
}
|
||||
|
||||
/* Add a number of months to a time value
|
||||
|
||||
Add a number of months to a time value, and normalize. Optionally
|
||||
also track the last day of the month, i.e. 1/31 -> 2/28 -> 3/30.
|
||||
|
||||
param tm: base time value
|
||||
param months: The number of months to add to this time
|
||||
param track_last_day: Coerce the date value if necessary.
|
||||
|
||||
return void
|
||||
*/
|
||||
void date_add_months (struct tm *tm, int months, gboolean track_last_day)
|
||||
{
|
||||
gboolean was_last_day;
|
||||
int new_last_mday;
|
||||
|
||||
/* Have to do this now */
|
||||
was_last_day = date_is_last_mday(tm);
|
||||
|
||||
/* Add in the months and normalize */
|
||||
tm->tm_mon += months;
|
||||
while (tm->tm_mon > 11) {
|
||||
tm->tm_mon -= 12;
|
||||
tm->tm_year++;
|
||||
}
|
||||
|
||||
if (!track_last_day)
|
||||
return;
|
||||
|
||||
/* Track last day of the month, i.e. 1/31 -> 2/28 -> 3/31 */
|
||||
new_last_mday = date_get_last_mday(tm);
|
||||
if (was_last_day || (tm->tm_mday > new_last_mday))
|
||||
tm->tm_mday = new_last_mday;
|
||||
}
|
||||
|
||||
/* Return the set dateFormat.
|
||||
|
||||
return QofDateFormat: enumeration indicating preferred format
|
||||
@@ -1429,61 +1394,5 @@ gnc_timet_get_today_end (void)
|
||||
return mktime(&tm);
|
||||
}
|
||||
|
||||
gboolean
|
||||
qof_date_add_days(Timespec *ts, gint days)
|
||||
{
|
||||
struct tm tm;
|
||||
time_t tt;
|
||||
|
||||
g_return_val_if_fail(ts, FALSE);
|
||||
tt = timespecToTime_t(*ts);
|
||||
#ifdef HAVE_GMTIME_R
|
||||
tm = *gmtime_r(&tt, &tm);
|
||||
#else
|
||||
tm = *gmtime(&tt);
|
||||
#endif
|
||||
tm.tm_mday += days;
|
||||
/* let mktime normalise the months and year
|
||||
because we aren't tracking last_day_of_month */
|
||||
tt = mktime(&tm);
|
||||
if(tt < 0) { return FALSE; }
|
||||
timespecFromTime_t(ts, tt);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
qof_date_add_months(Timespec *ts, gint months, gboolean track_last_day)
|
||||
{
|
||||
struct tm tm;
|
||||
time_t tt;
|
||||
gint new_last_mday;
|
||||
gboolean was_last_day;
|
||||
|
||||
g_return_val_if_fail(ts, FALSE);
|
||||
tt = timespecToTime_t(*ts);
|
||||
#ifdef HAVE_GMTIME_R
|
||||
tm = *gmtime_r(&tt, &tm);
|
||||
#else
|
||||
tm = *gmtime(&tt);
|
||||
#endif
|
||||
was_last_day = date_is_last_mday(&tm);
|
||||
tm.tm_mon += months;
|
||||
while (tm.tm_mon > 11) {
|
||||
tm.tm_mon -= 12;
|
||||
tm.tm_year++;
|
||||
}
|
||||
if (track_last_day) {
|
||||
/* Track last day of the month, i.e. 1/31 -> 2/28 -> 3/31 */
|
||||
new_last_mday = date_get_last_mday(&tm);
|
||||
if (was_last_day || (tm.tm_mday > new_last_mday)) {
|
||||
tm.tm_mday = new_last_mday;
|
||||
}
|
||||
}
|
||||
tt = mktime(&tm);
|
||||
if(tt < 0) { return FALSE; }
|
||||
timespecFromTime_t(ts, tt);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/********************** END OF FILE *********************************\
|
||||
\********************************************************************/
|
||||
|
||||
@@ -243,28 +243,6 @@ gchar * gnc_timespec_to_iso8601_buff (Timespec ts, gchar * buff);
|
||||
* routine might return incorrect values for dates before 1970. */
|
||||
void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year);
|
||||
|
||||
/** \brief Add a number of days to a Timespec and normalise.
|
||||
|
||||
Together with qof_date_add_months, replaces date_add_months.
|
||||
|
||||
\return FALSE on error, otherwise TRUE.
|
||||
*/
|
||||
gboolean qof_date_add_days(Timespec *ts, gint days);
|
||||
|
||||
/** \brief Add a number of months to a Timespec and normalise.
|
||||
|
||||
Optionally track the last day of the month so that adding one
|
||||
month to 31st January returns 28th February (29th in a leap year)
|
||||
and adding three months returns 30th April.
|
||||
|
||||
\return FALSE on error, otherwise TRUE.
|
||||
*/
|
||||
gboolean qof_date_add_months(Timespec *ts, gint months, gboolean track_last_day);
|
||||
|
||||
/** \deprecated Add a number of months to a time value and normalize. Optionally
|
||||
* also track the last day of the month, i.e. 1/31 -> 2/28 -> 3/31. */
|
||||
void date_add_months (struct tm *tm, gint months, gboolean track_last_day);
|
||||
|
||||
/** \warning hack alert XXX FIXME -- these date routines return incorrect
|
||||
* values for dates before 1970. Most of them are good only up
|
||||
* till 2038. This needs fixing ...
|
||||
|
||||
Reference in New Issue
Block a user