|
GnuCash 2.4.99
|
Files | |
| file | gnc-gdate-utils.h |
GDate helper routines. | |
GDate hash table support | |
| gint | gnc_gdate_equal (gconstpointer gda, gconstpointer gdb) |
| guint | gnc_gdate_hash (gconstpointer gd) |
GDate to time_t conversions | |
| time_t | gnc_timet_get_day_start_gdate (GDate *date) |
| time_t | gnc_timet_get_day_end_gdate (GDate *date) |
Date Manipulation | |
| void | gnc_gdate_set_month_start (GDate *date) |
| void | gnc_gdate_set_month_end (GDate *date) |
| void | gnc_gdate_set_prev_month_start (GDate *date) |
| void | gnc_gdate_set_prev_month_end (GDate *date) |
| void | gnc_gdate_set_quarter_start (GDate *date) |
| void | gnc_gdate_set_quarter_end (GDate *date) |
| void | gnc_gdate_set_prev_quarter_start (GDate *date) |
| void | gnc_gdate_set_prev_quarter_end (GDate *date) |
| void | gnc_gdate_set_year_start (GDate *date) |
| void | gnc_gdate_set_year_end (GDate *date) |
| void | gnc_gdate_set_prev_year_start (GDate *date) |
| void | gnc_gdate_set_prev_year_end (GDate *date) |
| void | gnc_gdate_set_fiscal_year_start (GDate *date, const GDate *year_end) |
| void | gnc_gdate_set_fiscal_year_end (GDate *date, const GDate *year_end) |
| void | gnc_gdate_set_prev_fiscal_year_start (GDate *date, const GDate *year_end) |
| void | gnc_gdate_set_prev_fiscal_year_end (GDate *date, const GDate *year_end) |
This file provides routines that help make it easier to use GDates from within Gnucash. A GDate is a data strucutre provided by GLib that handles dates from year 1 to year 9999.
| gint gnc_gdate_equal | ( | gconstpointer | gda, |
| gconstpointer | gdb | ||
| ) |
Compares two GDate*'s for equality; useful for using GDate*'s as GHashTable keys.
Definition at line 32 of file gnc-gdate-utils.c.
{
return (g_date_compare( (GDate*)gda, (GDate*)gdb ) == 0 ? TRUE : FALSE);
}
| guint gnc_gdate_hash | ( | gconstpointer | gd | ) |
Provides a "hash" of a GDate* value; useful for using GDate*'s as GHashTable keys.
Definition at line 38 of file gnc-gdate-utils.c.
{
gint val = (g_date_get_year( (GDate*)gd ) * 10000)
+ (g_date_get_month( (GDate*)gd ) * 100)
+ g_date_get_day( (GDate*)gd );
return g_int_hash( &val );
}
| void gnc_gdate_set_fiscal_year_end | ( | GDate * | date, |
| const GDate * | year_end | ||
| ) |
This function modifies a GDate to set it to the last day of the fiscal year in which it falls. For example, if this function is called with a date of 2003-09-24 and a fiscal year ending July 31st, the date will be modified to 2004-07-31.
| date | The GDate to modify. |
| year_end | A GDate containing the last month and day of the fiscal year. The year field of this argument is ignored. |
Definition at line 246 of file gnc-gdate-utils.c.
{
GDate temp;
gboolean new_fy;
g_return_if_fail(date);
g_return_if_fail(fy_end);
/* Compute the FY end that occurred this CY */
temp = *fy_end;
g_date_set_year(&temp, g_date_get_year(date));
/* Has it already passed? */
new_fy = (g_date_compare(date, &temp) > 0);
/* Set end date */
*date = temp;
if (new_fy)
g_date_add_years(date, 1);
}
| void gnc_gdate_set_fiscal_year_start | ( | GDate * | date, |
| const GDate * | year_end | ||
| ) |
This function modifies a GDate to set it to the first day of the fiscal year in which it falls. For example, if this function is called with a date of 2003-09-24 and a fiscal year ending July 31st, the date will be modified to 2003-08-01.
| date | The GDate to modify. |
| year_end | A GDate containing the last month and day of the fiscal year. The year field of this argument is ignored. |
Definition at line 222 of file gnc-gdate-utils.c.
{
GDate temp;
gboolean new_fy;
g_return_if_fail(date);
g_return_if_fail(fy_end);
/* Compute the FY end that occurred this CY */
temp = *fy_end;
g_date_set_year(&temp, g_date_get_year(date));
/* Has it already passed? */
new_fy = (g_date_compare(date, &temp) > 0);
/* Set start date */
*date = temp;
g_date_add_days(date, 1);
if (!new_fy)
g_date_subtract_years(date, 1);
}
| void gnc_gdate_set_month_end | ( | GDate * | date | ) |
This function modifies a GDate to set it to the last day of the month in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-09-30.
| date | The GDate to modify. |
Convert a GDate to the last day of the month. This routine has no knowledge of how many days are in a month, whether its a leap year, etc. All that information is contained in the glib date functions.
| date | The GDate to modify. |
Definition at line 97 of file gnc-gdate-utils.c.
{
/* First set the start of next month. */
g_date_set_day(date, 1);
g_date_add_months(date, 1);
/* Then back up one day */
g_date_subtract_days(date, 1);
}
| void gnc_gdate_set_month_start | ( | GDate * | date | ) |
This function modifies a GDate to set it to the first day of the month in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-09-01.
| date | The GDate to modify. |
Definition at line 83 of file gnc-gdate-utils.c.
{
g_date_set_day(date, 1);
}
| void gnc_gdate_set_prev_fiscal_year_end | ( | GDate * | date, |
| const GDate * | year_end | ||
| ) |
This function modifies a GDate to set it to the last day of the fiscal year prior to the one in which it falls. For example, if this function is called with a date of 2003-09-24 and a fiscal year ending July 31st, the date will be modified to 2003-07-31.
| date | The GDate to modify. |
| year_end | A GDate containing the last month and day of the fiscal year. The year field of this argument is ignored. |
Definition at line 280 of file gnc-gdate-utils.c.
{
g_return_if_fail(date);
g_return_if_fail(fy_end);
gnc_gdate_set_fiscal_year_end(date, fy_end);
g_date_subtract_years(date, 1);
}
| void gnc_gdate_set_prev_fiscal_year_start | ( | GDate * | date, |
| const GDate * | year_end | ||
| ) |
This function modifies a GDate to set it to the first day of the fiscal year prior to the one in which it falls. For example, if this function is called with a date of 2003-09-24 and a fiscal year ending July 31st, the date will be modified to 2002-08-01.
| date | The GDate to modify. |
| year_end | A GDate containing the last month and day of the fiscal year. The year field of this argument is ignored. |
Definition at line 269 of file gnc-gdate-utils.c.
{
g_return_if_fail(date);
g_return_if_fail(fy_end);
gnc_gdate_set_fiscal_year_start(date, fy_end);
g_date_subtract_years(date, 1);
}
| void gnc_gdate_set_prev_month_end | ( | GDate * | date | ) |
This function modifies a GDate to set it to the last day of the month prior to the one in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-08-31.
| date | The GDate to modify. |
Convert a GDate to the last day of the prebvious month. This routine has no knowledge of how many days are in a month, whether its a leap year, etc. All that information is contained in the glib date functions.
| date | The GDate to modify. |
Definition at line 131 of file gnc-gdate-utils.c.
{
/* This will correctly handle the varying month lengths */
g_date_set_day(date, 1);
g_date_subtract_days(date, 1);
}
| void gnc_gdate_set_prev_month_start | ( | GDate * | date | ) |
This function modifies a GDate to set it to the first day of the month prior to the one in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-08-01.
| date | The GDate to modify. |
Convert a GDate to the first day of the prebvious month. This routine has no knowledge of how many days are in a month, whether its a leap year, etc. All that information is contained in the glib date functions.
| date | The GDate to modify. |
Definition at line 116 of file gnc-gdate-utils.c.
{
g_date_set_day(date, 1);
g_date_subtract_months(date, 1);
}
| void gnc_gdate_set_prev_quarter_end | ( | GDate * | date | ) |
This function modifies a GDate to set it to the last day of the quarter prior to the one in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-07-31.
| date | The GDate to modify. |
Definition at line 180 of file gnc-gdate-utils.c.
{
gnc_gdate_set_quarter_end(date);
g_date_subtract_months(date, 3);
}
| void gnc_gdate_set_prev_quarter_start | ( | GDate * | date | ) |
This function modifies a GDate to set it to the first day of the quarter prior to the one in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-06-01.
| date | The GDate to modify. |
Definition at line 172 of file gnc-gdate-utils.c.
{
gnc_gdate_set_quarter_start(date);
g_date_subtract_months(date, 3);
}
| void gnc_gdate_set_prev_year_end | ( | GDate * | date | ) |
This function modifies a GDate to set it to the last day of the year prior to the one in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2002-12-31.
| date | The GDate to modify. |
Definition at line 213 of file gnc-gdate-utils.c.
{
gnc_gdate_set_year_end(date);
g_date_subtract_years(date, 1);
}
| void gnc_gdate_set_prev_year_start | ( | GDate * | date | ) |
This function modifies a GDate to set it to the first day of the year prior to the one in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2002-01-01.
| date | The GDate to modify. |
Definition at line 205 of file gnc-gdate-utils.c.
{
gnc_gdate_set_year_start(date);
g_date_subtract_years(date, 1);
}
| void gnc_gdate_set_quarter_end | ( | GDate * | date | ) |
This function modifies a GDate to set it to the last day of the quarter in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-12-31.
| date | The GDate to modify. |
Definition at line 155 of file gnc-gdate-utils.c.
{
gint months;
/* Set the date to the first day of the specified month. */
g_date_set_day(date, 1);
/* Add 1-3 months to get the first day of the next quarter.*/
months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
g_date_add_months(date, 3 - months);
/* Now back up one day */
g_date_subtract_days(date, 1);
}
| void gnc_gdate_set_quarter_start | ( | GDate * | date | ) |
This function modifies a GDate to set it to the first day of the quarter in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-09-01.
| date | The GDate to modify. |
Definition at line 141 of file gnc-gdate-utils.c.
{
gint months;
/* Set the date to the first day of the specified month. */
g_date_set_day(date, 1);
/* Back up 0-2 months */
months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
g_date_subtract_months(date, months);
}
| void gnc_gdate_set_year_end | ( | GDate * | date | ) |
This function modifies a GDate to set it to the last day of the year in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-12-31.
| date | The GDate to modify. |
Definition at line 197 of file gnc-gdate-utils.c.
{
g_date_set_month(date, G_DATE_DECEMBER);
g_date_set_day(date, 31);
}
| void gnc_gdate_set_year_start | ( | GDate * | date | ) |
This function modifies a GDate to set it to the first day of the year in which it falls. For example, if this function is called with a date of 2003-09-24 the date will be modified to 2003-01-01.
| date | The GDate to modify. |
Definition at line 189 of file gnc-gdate-utils.c.
{
g_date_set_month(date, G_DATE_JANUARY);
g_date_set_day(date, 1);
}
| time_t gnc_timet_get_day_end_gdate | ( | GDate * | date | ) |
The gnc_timet_get_day_end() routine will take the given time in GLib GDate format and adjust it to the last second of that day.
Definition at line 62 of file gnc-gdate-utils.c.
{
struct tm stm;
time_t secs;
/* First convert to a 'struct tm' */
g_date_to_struct_tm(date, &stm);
/* Force to th last second of the day */
stm.tm_hour = 23;
stm.tm_min = 59;
stm.tm_sec = 59;
stm.tm_isdst = -1;
/* Then convert to number of seconds */
secs = mktime (&stm);
return secs;
}
| time_t gnc_timet_get_day_start_gdate | ( | GDate * | date | ) |
The gnc_timet_get_day_start() routine will take the given time in GLib GDate format and adjust it to the first second of that day.
Definition at line 48 of file gnc-gdate-utils.c.
{
struct tm stm;
time_t secs;
/* First convert to a 'struct tm' */
g_date_to_struct_tm(date, &stm);
/* Then convert to number of seconds */
secs = mktime (&stm);
return secs;
}
1.7.4