|
|
|
|
|
|
|
5.1.2
Functions for the Parts of a Month |
|
|
|
|
|
|
|
|
The next set of basic functions is concerned with the parts of a month, such as the number of days in a month or the names of the months. |
|
|
|
|
|
|
|
|
days_in_month () returns the number of days in a given month for the Western (Julian and Gregorian) calendar. |
|
|
|
|
|
|
|
|
days_in_month_for_year () returns the number of days in a given month for a given year for the Western (Julian and Gregorian) calendar. |
|
|
|
|
|
|
|
|
month_name () returns the name of a month for an integer in the range 112 representing the month number. The month name is in English. The Western (Julian and Gregorian) calendar is assumed. |
|
|
|
|
|
|
|
|
month_name_military () returns the abbreviated military name of a month from an integer in the range 112 representing the month number. |
|
|
|
|
|
|
|
|
5.1.3
Leap Year Functions |
|
|
|
|
|
|
|
|
Because the Western calendar consists of two juxtaposed calendars, there are two leap year rules. Leap year functions return a type int argument, which takes the value 0 for common years and 1 for leap years. This choice of return values allows the functions to be used in two different ways: |
|
|
|
|
|
|
|
|
The returned values can be used as indicators of leap year, in a yes-or-no mode. |
|
|
|
|
|
|
|
|
The returned value can be added directly to a variable representing day number or number of days in a year. The value of 0 for common years has no effect, whereas the value 1 for leap years increments the variable by the desired unit amount. |
|
|
|
|
|
|
|
|
The Gregorian leap year function is shown in Listing 5.3 (page 87). The Julian leap year function [julian_leap_year ()] is on the companion CD-ROM. |
|
|
|
|
|
|
|
|
The long_mod () function may seem redundant, because the type long variable can be processed by the C modulus operator (%), just as the type int variable is. Some compilers, unfortunately, do not implement the modulus operator properly for type long. Because the failure of this operator to function correctly would contaminate the results of calculations for a large number of calendars, the SCDTL system bypasses this problem by implementing a type long modulus function separately. |
|
|
|
|
|