RTEMS
clocktodvalidate.c
Go to the documentation of this file.
1 
8 /*
9  * COPYRIGHT (c) 1989-2007.
10  * On-Line Applications Research Corporation (OAR).
11  *
12  * The license and distribution terms for this file may be
13  * found in the file LICENSE in this distribution or at
14  * http://www.rtems.org/license/LICENSE.
15  */
16 
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <rtems/rtems/clock.h>
22 #include <rtems/score/todimpl.h>
23 #include <rtems/config.h>
24 
25 /*
26  * The following array contains the number of days in all months.
27  * The first dimension should be 1 for leap years, and 0 otherwise.
28  * The second dimension should range from 1 to 12 for January to
29  * February, respectively.
30  */
31 const uint32_t _TOD_Days_per_month[ 2 ][ 13 ] = {
32  { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
33  { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
34 };
35 
37  const rtems_time_of_day *the_tod
38 )
39 {
40  uint32_t days_in_month;
41  uint32_t ticks_per_second;
42 
43  ticks_per_second = TOD_MICROSECONDS_PER_SECOND /
45  if ((!the_tod) ||
46  (the_tod->ticks >= ticks_per_second) ||
47  (the_tod->second >= TOD_SECONDS_PER_MINUTE) ||
48  (the_tod->minute >= TOD_MINUTES_PER_HOUR) ||
49  (the_tod->hour >= TOD_HOURS_PER_DAY) ||
50  (the_tod->month == 0) ||
51  (the_tod->month > TOD_MONTHS_PER_YEAR) ||
52  (the_tod->year < TOD_BASE_YEAR) ||
53  (the_tod->day == 0) )
54  return false;
55 
56  if (((the_tod->year % 4) == 0 && (the_tod->year % 100 != 0)) ||
57  (the_tod->year % 400 == 0))
58  days_in_month = _TOD_Days_per_month[ 1 ][ the_tod->month ];
59  else
60  days_in_month = _TOD_Days_per_month[ 0 ][ the_tod->month ];
61 
62  if ( the_tod->day > days_in_month )
63  return false;
64 
65  return true;
66 }
This header file defines the Clock Manager API.
This header file defines parts of the application configuration information API.
bool _TOD_Validate(const rtems_time_of_day *the_tod)
%
This type is used to represent the calendar time in the Classic API.
Definition: types.h:258
#define TOD_MICROSECONDS_PER_SECOND
Definition: todimpl.h:92
#define TOD_HOURS_PER_DAY
Definition: todimpl.h:69
uint32_t day
This member represents the day of the month with values from 1 to 31.
Definition: types.h:273
Time of Day Handler API.
#define rtems_configuration_get_microseconds_per_tick()
Returns the number of microseconds per clock tick configured for this application.
Definition: config.h:205
uint32_t month
This member represents the month of the year with values from 1 to 12.
Definition: types.h:268
#define TOD_MONTHS_PER_YEAR
Definition: todimpl.h:59
#define TOD_SECONDS_PER_MINUTE
Definition: todimpl.h:49
#define TOD_MINUTES_PER_HOUR
Definition: todimpl.h:54
#define TOD_BASE_YEAR
Earliest year to which an time of day can be initialized.
Definition: todimpl.h:122
uint32_t ticks
This member represents the clock tick of the second with values from 0 to rtems_clock_get_ticks_per_s...
Definition: types.h:296
uint32_t hour
This member represents the hour of the day with values from 0 to 23.
Definition: types.h:278
uint32_t second
This member represents the second of the minute with values from 0 to 59.
Definition: types.h:290
uint32_t minute
This member represents the minute of the hour with values from 0 to 59.
Definition: types.h:284
uint32_t year
This member represents the year A.D.
Definition: types.h:262