Date/Time API Library Module

The date/time API library module has the file name datime.c. This module manipulates and converts dates and times.

Here is a list of functions in the date/time API library module:

- datime_month_name_2_num
- datime_month_num_2_name
- get_time
- datime_hour12_2_hour24
- datime_get_ampm
- get_ftime
- run_year
- days_in_month
- isleap
- juldate
- datdif

# Module Dependencies

The following modules are required along with this module:

- parse.c

# Module Header Files

This module requires the header file:

- stdhead.h

# Module Functions

## datime_month_name_2_num

    Prototype  : int datime_month_name_2_num(char *mname)
    Parameters :
          Name : mname
    Description: month name

    Returns    : month number upon success, zero otherwise

This function will convert a month name to a month number. Only the first three characters of the month name are compared so you may use the long or short month names. January is considered month one.

## datime_month_num_2_name

    Prototype  : int datime_month_num_2_name(int mnum, char *mname)
    Parameters :
          Name : mnum
    Description: month number (jan=1)

          Name : mname
    Description: output month name

    Returns    : TRUE upon success, FALSE otherwise

This function will translate a month number to the short month name. The output month name must already be allocated to sufficient size by the caller.

## get_time

    Prototype   : void get_time(char *buf)
    Parameters  :
          Name  : buf
    Description : returned date/time string

This function will format and place a date/time string into the returned date/time string. The format of the string will be a series of digits in the form:

       yyyymmddhhmmss

The string uses no delimiters and can therefore be considered fixed length. The returned date/time string must already be allocated by the caller to at least 15 bytes in length.

## datime_hour12_2_hour24

    Prototype  : int datime_hour12_2_hour24(char *itime, char *otime, int s_flag)
    Parameters :
          Name : itime
    Description: input time

          Name : otime
    Description: output time

          Name : s_flag
    Description: separator flag

    Returns    : TRUE upon success, FALSE otherwise

This function will convert a time string expressed in 12 hour format to a time string expressed in 24 format. The input time may be in any of the following formats:

- hh[:mm][:ss]p, hh[:mm][:ss] p, hh[:mm][:ss]pm, hh[:mm][:ss] pm
- hh[:mm][:ss]a, hh[:mm][:ss] a, hh[:mm][:ss]am, hh[:mm][:ss] am
- hh[:mm][:ss]m, hh[:mm][:ss] m, hh[:mm][:ss]n, hh[:mm][:ss] n

Where p and pm are the same, a and am are also the same. A trailing m indicates midnight and a trailing n indicates noon. When a trailing m or n is used, the time is assumed to be 12:00 regardless of any other hour/minute value. Spaces may or may not be present after the time and before the am or pm designator. The colon separator is required in the input time string. The separator flag is used to indicate whether the output time should have a colon separator. The minute and seconds fields are completely optional. The output time always contains two digits each for the hour, minute and optional seconds. The hour and minute are always present in the output time. Seconds are only present in the output time if present in the input time. Function returns the converted time loaded into the output time (which must already be allocated by the caller) upon success.

## datime_get_ampm

    Prototype  : static int datime_get_ampm(char *wrd, char *ap)
    Parameters :
          Name : wrd
    Description: time string

          Name : ap
    Description: output designator

    Returns    : TRUE upon success, FALSE otherwise

This private function will get the am, pm designator in the time string. If found, the designator will be removed from the time string and a single character will be loaded into the output designator. Acceptable designators in the time string are a, am, p, pm, n and m.

## get_ftime

    Prototype   : void get_ftime(char *tbuf)
    Parameters  :
          Name  : tbuf
    Description : returned date/time string

This function will format and return the current time string. Returned format is:

       yyyy/mm/dd hh:mm:ss

Buffer tbuf must already be allocated by the caller to a minimum size of 20 bytes.

## run_year

    Prototype   : int run_year(void)

    Returns     : run year upon success, zero otherwise

This function will get the year of program run via the get_time function.

## days_in_month

    Prototype  : int days_in_month(int year, int month)
    Parameters :
          Name : year
    Description: full year (with century)

          Name : month
    Description: month number (jan=1)

    Returns    : number of days in month upon success, zero otherwise

This function will determine the number of days in a month taking into account leap years.

## isleap

    Prototype  : int isleap(int year)
    Parameters :
          Name : year
    Description: full year (with century)

    Returns    : TRUE upon a leap year, FALSE otherwise

This function will determine whether the full year is a leap year.

## juldate

    Prototype  : int juldate(char *dte, int *julout)
    Parameters :
          Name : dte
    Description: input date (in the form yyyymmdd)

          Name : julout
    Description: output Julian number

    Returns    : TRUE upon success, FALSE otherwise

This function will convert the input date to a Julian value using DATIME_JUL_BASE (defined in this module) as the base year. Upon success the Julian number will be loaded into the output Julian number.

## datdif

    Prototype  : int datdif(char *d1, char *d2, int *difout)
    Parameters :
          Name : d1
    Description: input date 1 (in the form yyyymmdd)

          Name : d2
    Description: input date 2 (in the form yyyymmdd)

          Name : difout
    Description: output date difference

    Returns    : TRUE upon success, FALSE otherwise

This function will calculate the number of days difference between two dates. The input date 1 is assumed to be the later of the two dates. Upon success the number of days difference will be loaded into the output date difference.

Goto Top | GPL Software Overview | GPL Library
Future Lab Home | Contact Webmaster | Feedback

Copyright © 2002-2006 Future Lab, Last Updated Jun 30, 2006