GRASS Programmer's Manual
6.4.2(2012)
|
00001 /* 00002 * Copyright (C) 1995. Bill Brown <brown@gis.uiuc.edu> & Michael Shapiro 00003 * 00004 * This program is free software under the GPL (>=v2) 00005 * Read the file GPL.TXT coming with GRASS for details. 00006 */ 00007 #include <grass/datetime.h> 00008 00009 00018 int datetime_is_leap_year(int year, int ad) 00019 { 00020 if (year == 0) 00021 return datetime_error(-1, "datetime_is_leap_year(): illegal year"); 00022 if (!ad) 00023 return 0; /* BC */ 00024 if (year < 0) 00025 return 0; /* ?? */ 00026 00027 return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0); 00028 } 00029 00030 00041 int datetime_days_in_year(int year, int ad) 00042 { 00043 if (year == 0) 00044 return datetime_error(-1, "datetime_days_in_year(): illegal year"); 00045 00046 if (datetime_is_leap_year(year, ad)) 00047 return 366; 00048 else 00049 return 365; 00050 } 00051 00052 00064 int datetime_days_in_month(int year, int month, int ad) 00065 { 00066 static int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 00067 00068 if (month < 1 || month > 12) 00069 return datetime_error(-1, "datetime_days_in_month(): illegal month"); 00070 00071 if (month == 2 && datetime_is_leap_year(year, ad)) 00072 return (29); 00073 00074 return (days[month - 1]); 00075 }