Headers Index Help Within this page: Functions Constants Variables
- Written by M.C.Gregorie, 2011.
The functions in this package are based on the standard C date and time functions. Their purpose is to make date adjustments easier, e.g. to create a date 5 hours earlier or a month later than a base date, which defaults to 'now'. These functions operate on an internal stored time_t date/time value. There are three groups of functions in this package:
Functions for setting the stored date/time:
Functions for adjusting the stored date/time
Control functions
Functions for outputting the stored date/time:
All functions operate on a hidden global base date, so successive operations can be applied to make complex changes to a date. The ajgetdate() and ajsetdate() functions can be used to preserve the current base date value while you adjust other date(s).
The initial basedate value is set to zero, so you should always call ajsetnow() or ajsetdate() to initialise the base date before applying changes to it.
This collection of functions is compiled to form part of the libenviron.a library, which must be linked if any of of its constituent functions are called.
The calling programs should include adjustdate.h and must be linked using -lenviron.
environ - C programming support functions
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License.
This program 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 General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Copyright (C) 2005-2011 Martin C Gregorie
Contact Martin Gregorie at martin@gregorie.org
#include <adjustdate.h>
void ajdebug(int level);
Set debugging conditions.
When the debug level is zero no tracing occurs. A debug level of 1 traces calls to the functions in this package and is intended to help debugging the calling program.
A debug level of 2 or 3 can be used to trace the internals of the more complex functions on this package.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
int ajerror();
Returns TRUE if the last adjustdate function call set an error condition.
Calling ajgeterror() returns the error.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
char *ajformatdate(char *format);
Return the current base date as a local time string, formatted as defined in the supplied format string. The format string follows the conventions used by strftime.
Sets an error condition if the required string is too long for the internal formatted date buffer.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
time_t ajgetdate();
Return the current basedate value.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
char *ajgeterror();
Return a string describing the last error detected.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
void ajmonth(int offset, int day);
Move the date by 'offset' months, adjusting the year as needed. Offset may be signed: a positive value increments the month number. The day of the month is set to the 'day' value after offsetting the month and is checked to be in the range 1 to the last day of the month.
All range checks on the last day of the month take leap years into account.
Since it may difficult to determine the last day of the month you are altering, you can also use the constants FIRSTDAY, LASTDAY and KEEPDAY. The latter causes the day of month to remain unchanged, but if the day would be outside the target month, the state of the 'truncate' flag is used to determine whether to truncate the date to the last day of the month or to set the date to a day at the start of the following month.
See also ajoffsetdate() and ajtruncate().
Sets an error condition if errors are discovered and leaves the date unchanged.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
void ajoffsetdate(int offset, int element);
Adjust a date/time by adding the signed offset to the element of time, which may be DAY, HOUR, MIN, or SEC.
Sets an error condition if errors are discovered.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
void ajsetdate(time_t dt);
Set the base date to a known time.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
void ajsetnow();
Set the base date and time to 'now'.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
void ajtruncate(int setting);
Set the 'truncate' flag.
If the flag is ON, days that are outside the permitted range for the current month will be set to the last day of the month.
If the flag is OFF, the month number is incremented, which may also affect the year, and the day of the month is set to the difference between its original value and the final day of the originally selected month.
Leap years are included in this calculation.
The default setting for the 'truncate' flag is OFF.
Sets an error condition if the required setting is not ON or OFF.
In: adjustdate.c
Return to the top
#include <adjustdate.h>
void ajyear(int offset, int action);
Move the date by 'offset' years, leaving the time unchanged. Offset may be signed: a positive value increments the year. 'action' must be one of the constants FIRSTDAY, LASTDAY and KEEPDATE. It specifies the changes, if any, to be made to the month and day of month. FIRSTDAY sets the date to the 1st of January for the adjusted year while LASTDAY sets the date to the 31st of December for the adjusted year.
KEEPDATE leaves the month and day of month unchanged, but can be affected by day of the month truncation if the offset moves the date from a leap year to a non-leap year and the the original date was the 29th of February.
See also ajtruncate().
You can make additional adjustments with ajmonth() and ajoffsetdate().
Sets an error condition if errors are discovered.
In: adjustdate.c
Return to the topDAY | #define DAY -5 |
FIRSTDAY | #define FIRSTDAY -2 |
HOUR | #define HOUR -6 |
KEEPDATE | #define KEEPDATE -4 |
KEEPDAY | #define KEEPDAY -3 |
LASTDAY | #define LASTDAY -1 |
MIN | #define MIN -7 |
OFF | #define OFF 0 |
ON | #define ON -9 |
SEC | #define SEC -8 |
Public variables were not declared.
Return to the top