Added a test for MUIA_Listview_SelectChange.
[AROS.git] / rom / utility / checkdate.c
blob0379afb89a953bc0e490bfd8fd66f3cbd79f67c0
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: CheckDate() - is a date valid ?
6 Lang: english
7 */
8 #include "intern.h"
10 /*****************************************************************************
12 NAME */
13 #include <utility/date.h>
14 #include <proto/utility.h>
16 AROS_LH1(ULONG, CheckDate,
18 /* SYNOPSIS */
19 AROS_LHA(struct ClockData *, date, A0),
21 /* LOCATION */
22 struct Library *, UtilityBase, 22, Utility)
24 /* FUNCTION
25 Examine the date described in the ClockData structure and
26 determine whether it is a valid date. In particular this
27 checks whether the ranges of the fields are within normal
28 limits.
30 This function does not check whether the wday field of the
31 ClockData structure is valid.
33 INPUTS
34 date - A ClockData structure desribing the date
35 to check.
37 RESULT
38 If the date is valid, the number of seconds from midnight
39 1-Jan-1978 AD to the date, or 0 if the date is invalud.
41 NOTES
42 The date 01-Jan-78 00:00:00 is actually returned as invalid.
44 This also assumes that the ClockDate refers to a date in the
45 Gregorian calendar. (60 sec/min, 60 min/hour, 24 hr/day,
46 12 months/year).
48 EXAMPLE
50 BUGS
51 Does not check whether the 29/2 is valid outside of a leap year.
53 SEE ALSO
54 Amiga2Date(), Date2Amiga()
56 INTERNALS
57 Since all the values are unsigned, we don't have to check for < 0
58 in fields which range from 0 ... n.
60 HISTORY
61 29-10-95 digulla automatically created from
62 utility_lib.fd and clib/utility_protos.h
64 *****************************************************************************/
66 AROS_LIBFUNC_INIT
68 /* Note: 60!!! This is in case of any future leap seconds... */
69 if( date->sec > 60 )
70 return 0;
72 if( date->min > 59)
73 return 0;
75 if( date->hour > 23)
76 return 0;
78 /* XXX: When does the year become invalid? */
79 if( date->year < 1978 )
80 return 0;
82 if( date->wday > 6)
83 return 0;
85 if( date->mday < 1 )
86 return 0;
88 switch( date->month )
90 /* 30 days hath September, April, June and November */
91 case 4:
92 case 6:
93 case 9:
94 case 11:
95 if(date->mday > 30)
96 return 0;
97 break;
99 /* And all the rest have 31 ... */
100 case 1:
101 case 3:
102 case 5:
103 case 7:
104 case 8:
105 case 10:
106 case 12:
107 if(date->mday > 31)
108 return 0;
109 break;
111 /* Except February with has 28, or 29 on a leap year,
112 should I check whether this is a leap year or not?
114 case 2:
115 if(date->mday > 29)
116 return 0;
117 break;
119 /* This also traps invalid month numbers */
120 default:
121 return 0;
122 } /* switch(date->month) */
124 return Date2Amiga(date);
126 AROS_LIBFUNC_EXIT
127 } /* CheckDate */