source: rtems/cpukit/rtems/src/clocktodvalidate.c @ f6e0934

4.104.114.84.95
Last change on this file since f6e0934 was f6e0934, checked in by Joel Sherrill <joel.sherrill@…>, on 04/02/07 at 21:51:52

2007-04-02 Joel Sherrill <joel@…>

  • posix/include/rtems/posix/timer.h, posix/src/alarm.c, posix/src/posixtimespectointerval.c, posix/src/ptimer1.c, posix/src/sysconf.c, posix/src/ualarm.c, rtems/src/clockget.c, rtems/src/clocktodvalidate.c, score/include/rtems/score/tod.h, score/inline/rtems/score/tod.inl, score/src/coretod.c: Eliminate TOD_Ticks_per_second variable.
  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 *  Time of Day (TOD) Handler -- Validate Classic TOD
3 *
4 *
5 *  COPYRIGHT (c) 1989-2007.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/rtems/clock.h>
21
22/*
23 *  The following array contains the number of days in all months.
24 *  The first dimension should be 1 for leap years, and 0 otherwise.
25 *  The second dimension should range from 1 to 12 for January to
26 *  February, respectively.
27 */
28const uint32_t   _TOD_Days_per_month[ 2 ][ 13 ] = {
29  { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
30  { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
31};
32
33/*PAGE
34 *
35 *  _TOD_Validate
36 *
37 *  This kernel routine checks the validity of a date and time structure.
38 *
39 *  Input parameters:
40 *    the_tod - pointer to a time and date structure
41 *
42 *  Output parameters:
43 *    TRUE  - if the date, time, and tick are valid
44 *    FALSE - if the the_tod is invalid
45 *
46 *  NOTE: This routine only works for leap-years through 2099.
47 */
48
49boolean _TOD_Validate(
50  rtems_time_of_day *the_tod
51)
52{
53  uint32_t   days_in_month;
54
55  if ((!the_tod)                                  ||
56      (the_tod->ticks  >=
57          (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick))  ||
58      (the_tod->second >= TOD_SECONDS_PER_MINUTE) ||
59      (the_tod->minute >= TOD_MINUTES_PER_HOUR)   ||
60      (the_tod->hour   >= TOD_HOURS_PER_DAY)      ||
61      (the_tod->month  == 0)                      ||
62      (the_tod->month  >  TOD_MONTHS_PER_YEAR)    ||
63      (the_tod->year   <  TOD_BASE_YEAR)          ||
64      (the_tod->day    == 0) )
65     return FALSE;
66
67  if ( (the_tod->year % 4) == 0 )
68    days_in_month = _TOD_Days_per_month[ 1 ][ the_tod->month ];
69  else
70    days_in_month = _TOD_Days_per_month[ 0 ][ the_tod->month ];
71
72  if ( the_tod->day > days_in_month )
73    return FALSE;
74
75  return TRUE;
76}
Note: See TracBrowser for help on using the repository browser.