source: rtems/cpukit/rtems/src/clocktodvalidate.c @ 66cb142

Last change on this file since 66cb142 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
RevLine 
[a6500136]1/**
2 *  @file
[93b4e6ef]3 *
[a6500136]4 *  @brief TOD Validate
5 *  @ingroup ClassicClock
6 */
7
8/*
[812da54]9 *  COPYRIGHT (c) 1989-2007.
[93b4e6ef]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
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[93b4e6ef]15 */
16
[a8eed23]17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
[812da54]21#include <rtems/rtems/clock.h>
[f031df0e]22#include <rtems/score/todimpl.h>
[88c74ab]23#include <rtems/config.h>
[812da54]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};
[93b4e6ef]35
[484a769]36bool _TOD_Validate(
[9d06996]37  const rtems_time_of_day *the_tod
[93b4e6ef]38)
39{
[3127180]40  uint32_t   days_in_month;
[3d66dfc1]41  uint32_t   ticks_per_second;
[93b4e6ef]42
[05c1886]43  ticks_per_second = TOD_MICROSECONDS_PER_SECOND /
[3d66dfc1]44            rtems_configuration_get_microseconds_per_tick();
[e980b219]45  if ((!the_tod)                                  ||
[3d66dfc1]46      (the_tod->ticks  >= ticks_per_second)       ||
[93b4e6ef]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) )
[484a769]54     return false;
[93b4e6ef]55
[8ed1a54c]56  if (((the_tod->year % 4) == 0 && (the_tod->year % 100 != 0)) ||
57     (the_tod->year % 400 == 0))
[93b4e6ef]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 )
[484a769]63    return false;
[93b4e6ef]64
[484a769]65  return true;
[93b4e6ef]66}
Note: See TracBrowser for help on using the repository browser.