#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "config.h"
#include "date.h"
Defines | |
#define | modulo(x,y) ((x)%(y)<0?(x)%(y)+(y):(x)%(y)) |
#define | DT_event_is_in_range(d,e) |
Functions | |
DT_DATE* | DT_mkdate (int year, int month, int day) |
DT_DATE* | DT_mkdate_dow (int ordinal, int dow, int month, int year) |
DT_DATE* | DT_mkdate_rata_die (long int rata_die) |
DT_DATE* | DT_copy_date (DT_DATE *date) |
void | DT_rmdate (DT_DATE *date) |
long int | DT_days_between (DT_DATE *date1, DT_DATE *date2) |
long int | DT_months_between (DT_DATE *date1, DT_DATE *date2) |
char* | DT_ascii (DT_DATE *date, unsigned long int format) |
char* | DT_ascii_r (char *buffer, int buf_size, DT_DATE *date, unsigned long int format) |
char* | DT_dow_ascii (DT_DATE *date) |
void | DT_set_date (DT_DATE *date, int year, int month, int day) |
void | DT_set_rata_die (DT_DATE *date, long int rata_die) |
int | DT_dow (DT_DATE *date) |
void | DT_gregorian_date (DT_DATE *date) |
int | DT_year (DT_DATE *date) |
int | DT_month (DT_DATE *date) |
int | DT_day (DT_DATE *date) |
long int | DT_rata_die (DT_DATE *date) |
void | DT_add_months (DT_DATE *date, long int months) |
void | DT_add_days (DT_DATE *date, long int days) |
void | DT_find_dow_date (DT_DATE *date, int ordinal, int dow, int month) |
int | DT_days_this_month (DT_DATE *date) |
int | DT_days_this_month_q (int year, int month) |
void | DT_easter (DT_DATE *date) |
DT_EVENT* | DT_mkevent (DT_DATE *start, DT_DATE *end, long int interval) |
DT_EVENT* | DT_mkevent_monthly (DT_DATE *start, DT_DATE *end, long int interval, int day) |
DT_EVENT* | DT_mkevent_monthly_dow (DT_DATE *start, DT_DATE *end, long int interval, int ordinal, int dow) |
void | DT_rmevent (DT_EVENT *event, int freeall) |
void | DT_event_adj_rel (DT_EVENT *event, int adj) |
void | DT_event_adj_dow (DT_EVENT *event, int sign, int dow) |
void | DT_event_multiday (DT_EVENT *event, int len) |
void | DT_event_pattern (DT_EVENT *event, char *pattern) |
void | DT_event_calc_adj (DT_DATE *date, DT_EVENT *event) |
int | DT_event_check_pattern (DT_DATE *start_date, DT_EVENT *event, DT_DATE *target_date) |
void | DT_event_calc_from_seed (DT_DATE *date, DT_EVENT *event) |
void | DT_event_closest (DT_DATE *date, DT_EVENT *event) |
void | DT_event_next_block (DT_DATE *event_date, DT_EVENT *event) |
int | DT_is_event_today (DT_DATE *date, DT_EVENT *event) |
DT_DATE* | DT_event_next (DT_DATE *date, DT_EVENT *event) |
int | DT_cal_rows (DT_DATE *date) |
int | DT_cal_day_to_row (DT_DATE *date) |
int | DT_cal_day_to_col (DT_DATE *date) |
int | DT_cal_row_col_to_day (DT_DATE *date, int row, int col) |
double | DT_moon_age (DT_DATE *date, int timezone) |
Variables | |
char* | month [] |
char* | dow [] |
int | days_per_month [] |
Copyright (C) 2000 James Williams
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Initial value:
\ ((d)->rata_die >= (e)->start_date->rata_die \ && ((e)->end_date == NULL \ || (d)->rata_die <= (e)->end_date->rata_die))
|
Modulo function that works correctly for negative divisors.
|
DT_add_days.
Adds some number of days to the date.
date | The date to adjust. |
days |
The number of days to add.
|
|
DT_add_months.
Adds some number of months to the date.
date | The date to adjust. |
months |
The number of months to add.
|
|
DT_ascii.
Converts a date into ascii format suitable for displaying to the user. The format can be in one of several formats, which are DT_US_FORMAT, DT_EUROPE_FORMAT, or DT_UNIVERSAL_FORMAT. This symbol can be ORed with DT_NUMERIC_OUT if you want the output to be strictly numeric. The result will be stored in a statically declared buffer.
date | The date to convert |
format |
The desired output format, as described above
|
|
DT_ascii_r.
Converts a date into ascii format suitable for displaying to the user. The format can be in one of several formats, which are DT_US_FORMAT, DT_EUROPE_FORMAT, or DT_UNIVERSAL_FORMAT. This symbol can be ORed with DT_NUMERIC_OUT if you want the output to be strictly numeric. The result will be stored in a statically declared buffer.
buffer | The buffer where the output will be held |
buf_size | The size of the buffer |
date | The date to convert |
format |
The desired output format, as described above
|
|
DT_cal_day_to_col.
Given a date, return the column in which it would appear in the calendar.
date |
The date the convert
|
|
DT_cal_day_to_row.
Given a date, return the row in which it would appear in the calendar.
date |
The date the convert
|
|
DT_cal_row_col_to_day.
Given a month, row, and column, determine which day of the month should fill that location.
date | The DT_DATE structure containing the month and year. |
row | The row of the calendar (0-5) |
col |
The column of the calendar (0-6)
|
|
DT_cal_rows.
Determines how many rows would be in a rendered calendar for a given month.
date |
The DT_DATE structure holding the year and month to check
|
|
DT_copy_date.
Creates a new date structure by copying the elements from an existing one.
date |
The date to copy
|
|
DT_day.
Returns the day part of the date.
date |
The date to extract the day from
|
|
DT_days_between.
Determines how many days are between two dates. It subtracts the second from the first, so if the second date is more recent than the first, the result will be negative.
date1 | The first date |
date2 |
The second date
|
|
DT_days_this_month.
Given a date structure set to some month, return the number of days in the month.
date |
The date whose month we want to check.
|
|
DT_days_this_month_q.
Given a date structure set to some month, return the number of days in the month. This version is meant to make a quick calculation without the need to create a date structure.
year | The year for the month we're interested in |
month |
The month we're interested in (1-12)
|
|
DT_dow.
Returns the day of week for the time stored in a DT_DATE structure.
date |
The date structure to use
|
|
DT_dow_ascii.
Given a date, returns a pointer to an ascii version of the day of the week for that date.
date |
The date to convert
|
|
DT_easter.
Calculate easter for a given year. The date calculated will be for the year contained in the date.
date |
The DT_DATE structure
|
|
DT_event_adj_dow.
Given an event, this allows one to adjust to a particular day of the week. The adjustment can be made either in the forward or reverse direction, will never exceed one week, and is guaranteed to change the date. As an example, if you wanted the first Monday after April 15, and April 15 is on a Friday, this would cause the event to be pushed 3 days forward. If April 15 is on a Monday, the event will be pushed 7 days forward. If you want to disable this feature from an event, use DT_NONE for the event, and anything you want for the dow.
event | The event to adjust |
sign | DT_NEXT, DT_PREV, or DT_NONE |
dow: |
The day of the week DT_SUNDAY, DT_MONDAY, etc.
|
|
DT_event_adj_rel.
Give an event a relative adjustment. What this means is that after calculating the day an event occurs on, add this many days to it. That way, you can, for example, calculate election day as the first Tuesday after the first Monday of November every fourth year. Just calculate the first Monday in November, then add 1 to it. That's what this function is for. Notice, however, that the days you add or subtract must not be greater than the interval for the event.
event | The event to adjust |
adj |
The number of days to add to an event day
|
|
DT_event_calc_adj.
Given a date and an event, adjust the date according to the day and day of week adjustments in the event structure. This assumes the date has already been set to match the event sans adjustment. This function is for internal use only.
date | The date to adjust |
event |
The event from which the adjustments will be taken
|
|
DT_event_calc_from_seed.
Given a "seed" date, calculates when the event associated with that seed occurs. Notice that this function is for internal use only.
date | The seed date |
event |
The event to calculate
|
|
DT_event_check_pattern.
Given a date which is assumed to be the beginning of an event, an event with a pattern, and a target date, determines if the event occurs on the target date. Notice that this function is for internal use only
start_date | The date when the event begins |
event | The event in question |
target_date |
The target date to test
|
|
DT_event_closest.
Find the start of the event on or before a given target date. This function doesn't consider the event's start and end dates. Notice that this function is for internal use only.
date | The target date |
event |
The event to find
|
|
DT_event_multiday.
Sets an event to last more than a single day. Using this function, every day of an event will be considered part of the event. For more complex patterns, use the DT_event_pattern function instead.
event | The event to adjust |
len |
How long to make the event.
|
|
DT_event_next.
Given a date and an event, find the next occurance of the event. Notice that if an event occurs on the date supplied, that date will not be returned.
date | The date to check around |
event |
The event to locate
|
|
DT_event_next_block.
Given a date which is the start of an event block, find the start of the next event block. Notice that this function is for internal use only.
event_date | The start of the event block |
event |
The event we are looking at
|
|
DT_event_pattern.
Sets a complex pattern for a multiday event. The input contains a string of 0's and 1's, with each character representing a single day. A 0 means the event does not take place on that day, while a 1 means it does.
event | The event to adjust |
pattern |
The pattern for the event
|
|
DT_find_dow_date.
Finds a date based on a day of week expression. For example, to find Thanksgiving, one would say the 4th Thursday in November. The year is taken from the current value in date. It is also possible, using DT_DAY for the day of week, to find the last day of the month (or the first, second, third, or fourth day of the month, but what's the use in that?)
date | The DT_DATE structure to modify |
ordinal | DT_FIRST, DT_SECOND, DT_THIRD, DT_FOURTH, or DT_LAST. |
dow | Day of week (0-6), or DT_DAY |
month |
The month (1-12)
|
|
DT_gregorian_date.
Internally calculates the gregorian date from the rata die. This function is for internal use only.
date |
The date structure
|
|
DT_is_event_today.
Determine if an event occurs on a particular day. Given an event and a date, determines if the event occurs on that day.
date | The DT_DATE structure containing the day |
event |
The DT_EVENT structure containing the event
|
|
DT_mkdate.
Create a DT_DATE structure from a given year, month, and date
year | The full year (not just the last two digits) |
month | The month (1=Jan, 2=Feb, ... , 11=Nov, 12=Dec) |
date |
The day of the month
|
|
DT_mkdate_dow.
Sets the date according to a particular occurance of a day of the week in some month and year. This can be used to, for example, find the first Sunday in April of 2000, or the last day in October of 2000.
ordinal | DT_FIRST, DT_SECOND, DT_THIRD, DT_FOURTH, or DT_LAST. |
dow | Day of week (0-6), or DT_DAY |
month | The month (1-12) |
year |
The year
|
|
DT_mkdate_rata_die.
Given a date in rata die format, it returns a DT_DATE structure for it.
rata_die |
The date in rata die format
|
|
DT_mkevent.
Create a basic, no frills event. The event will recur at regular intervals, such as a weekly event (but not a monthly one - see DT_mkevent_monthly for that), and have bracketing dates between which the event will occur (so you can create an event that will only occur for one year, for example).
start | The date on which the event first occurs. |
end | The date after which the event will no longer occur. If you want the event to continue indefinitely, set this to NULL. |
interval |
How long between one event and the next (in days)?
|
|
DT_mkevent_monthly.
Create an event that will recur on a certain day of the month every "interval" months. You can create a yearly event by setting the interval to 12. The event will first occur on the start day, and occur no further than the end date, thus allowing one to bracket the dates in which the event will occur. Set the end date to NULL if you want to event to recur indefinetely.
start | The date on which the event first occurs. |
end | The date after which the event will no longer occur. If you want the event to continue indefinitely, set this to NULL. |
interval | How long between one event and the next (in months)? |
day |
The day of the month for the event.
|
|
DT_mkevent_monthly_dow.
Create an event that will recur on a particular day of the week at some point in a given month. This can be used for events which occur, for example, on the third Wednesday of every month (or every other month, or whatever). You need to pass a date for the first occurance of the event, and optionally a date for the last occurance. This last occurance can be NULL if the event to recur indefinitely. You must also specify how many months between events. If you want the event to occur every third month, set interval to 3. The ordinal and dow arguments work the same as the ones in DT_find_dow_date.
start | The date on which the event first occurs. |
end | The date after which the event will no longer occur. If you want the event to continue indefinitely, set this to NULL. |
interval | How long between one event and the next (in months)? |
ordinal | DT_FIRST, DT_SECOND, DT_THIRD, DT_FOURTH, or DT_LAST |
dow |
A day of the week, or DT_DAY
|
|
DT_month.
Returns the month part of the date.
date |
The date to extract the month from
|
|
DT_months_between.
Determines how many months are between two dates. It subtracts the second from the first, so if the second date is more recent than the first, the result will be negative. Also, this function completely ignores the day of the month, so consecutive days in different months, like Jan 31 and Feb 1 will have a difference of 1.
date1 | The first date |
date2 |
The second date
|
|
DT_moon_age.
Calculate the age of the moon in its synodic month. A synodic month Is the time the moon takes to go though all its phases, from one new moon to the next. Once we know the age, we can infer the phase of the moon from it.
date | A DT_DATE structure for the date to calculate for. |
timezone |
The timezone, represented as the number of hours relative to GMT
|
|
DT_rata_die.
Returns the date in rata die format
date |
The date to extract the year from
|
|
DT_rmdate.
Frees a DT_DATE structure. Call this when you are finished using one.
date |
The DT_DATE structure to free
|
|
DT_rmevent.
Frees the memory associated with an event. It can optionally free the memory associated with the two date structures inside as well.
event | The event to free. |
freeall |
Either DT_FREE_ALL or DT_FREE_NONE, referring to whether or not to free the internal date structures.
|
|
DT_set_date.
Sets the date in a date structure.
date | The DT_DATE structure |
year | The year |
month | The month |
day |
The day of the month
|
|
DT_set_rata_die.
Sets the date in a date structure using the rata die format.
date | The DT_DATE structure |
rata_die |
The date in rata die format
|
|
DT_year.
Returns the year part of the date.
date |
The date to extract the year from
|
|
Initial value:
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
Initial value:
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
|
Initial value:
{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}