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

Last change on this file was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief TOD Validate
5 *  @ingroup ClassicClock
6 */
7
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#if 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 */
31const 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
36bool _TOD_Validate(
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 /
44            rtems_configuration_get_microseconds_per_tick();
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}
Note: See TracBrowser for help on using the repository browser.