GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
misc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1995. Bill Brown <brown@gis.uiuc.edu> & Michael Shapiro
3  *
4  * This program is free software under the GPL (>=v2)
5  * Read the file GPL.TXT coming with GRASS for details.
6  */
7 #include <grass/datetime.h>
8 
9 
18 int datetime_is_leap_year(int year, int ad)
19 {
20  if (year == 0)
21  return datetime_error(-1, "datetime_is_leap_year(): illegal year");
22  if (!ad)
23  return 0; /* BC */
24  if (year < 0)
25  return 0; /* ?? */
26 
27  return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
28 }
29 
30 
41 int datetime_days_in_year(int year, int ad)
42 {
43  if (year == 0)
44  return datetime_error(-1, "datetime_days_in_year(): illegal year");
45 
46  if (datetime_is_leap_year(year, ad))
47  return 366;
48  else
49  return 365;
50 }
51 
52 
64 int datetime_days_in_month(int year, int month, int ad)
65 {
66  static int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
67 
68  if (month < 1 || month > 12)
69  return datetime_error(-1, "datetime_days_in_month(): illegal month");
70 
71  if (month == 2 && datetime_is_leap_year(year, ad))
72  return (29);
73 
74  return (days[month - 1]);
75 }
int datetime_days_in_year(int year, int ad)
returns the number of days in &#39;year&#39;
Definition: misc.c:41
int datetime_is_leap_year(int year, int ad)
Definition: misc.c:18
int datetime_error(int code, char *msg)
record &#39;code&#39; and &#39;msg&#39; as error code/msg (in static variables) code==0 will clear the error (ie set ...
int datetime_days_in_month(int year, int month, int ad)
returns number of days in &#39;month&#39; of a particular &#39;year&#39;
Definition: misc.c:64