[93b4e6ef] | 1 | /* |
---|
[812da54] | 2 | * Time of Day (TOD) Handler -- Validate Classic TOD |
---|
[93b4e6ef] | 3 | * |
---|
| 4 | * |
---|
[812da54] | 5 | * COPYRIGHT (c) 1989-2007. |
---|
[93b4e6ef] | 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 |
---|
[dd687d97] | 10 | * http://www.rtems.com/license/LICENSE. |
---|
[93b4e6ef] | 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
[a8eed23] | 15 | #if HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
[93b4e6ef] | 19 | #include <rtems/system.h> |
---|
[3d66dfc1] | 20 | #include <rtems/config.h> |
---|
[812da54] | 21 | #include <rtems/rtems/clock.h> |
---|
| 22 | |
---|
| 23 | /* |
---|
| 24 | * The following array contains the number of days in all months. |
---|
| 25 | * The first dimension should be 1 for leap years, and 0 otherwise. |
---|
| 26 | * The second dimension should range from 1 to 12 for January to |
---|
| 27 | * February, respectively. |
---|
| 28 | */ |
---|
| 29 | const uint32_t _TOD_Days_per_month[ 2 ][ 13 ] = { |
---|
| 30 | { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, |
---|
| 31 | { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } |
---|
| 32 | }; |
---|
[93b4e6ef] | 33 | |
---|
| 34 | /*PAGE |
---|
| 35 | * |
---|
| 36 | * _TOD_Validate |
---|
| 37 | * |
---|
| 38 | * This kernel routine checks the validity of a date and time structure. |
---|
| 39 | * |
---|
| 40 | * Input parameters: |
---|
| 41 | * the_tod - pointer to a time and date structure |
---|
| 42 | * |
---|
| 43 | * Output parameters: |
---|
[eaef4657] | 44 | * true - if the date, time, and tick are valid |
---|
| 45 | * false - if the the_tod is invalid |
---|
[93b4e6ef] | 46 | * |
---|
| 47 | * NOTE: This routine only works for leap-years through 2099. |
---|
| 48 | */ |
---|
| 49 | |
---|
[484a769] | 50 | bool _TOD_Validate( |
---|
[812da54] | 51 | rtems_time_of_day *the_tod |
---|
[93b4e6ef] | 52 | ) |
---|
| 53 | { |
---|
[3127180] | 54 | uint32_t days_in_month; |
---|
[3d66dfc1] | 55 | uint32_t ticks_per_second; |
---|
[93b4e6ef] | 56 | |
---|
[3d66dfc1] | 57 | ticks_per_second = TOD_MICROSECONDS_PER_SECOND / |
---|
| 58 | rtems_configuration_get_microseconds_per_tick(); |
---|
[e980b219] | 59 | if ((!the_tod) || |
---|
[3d66dfc1] | 60 | (the_tod->ticks >= ticks_per_second) || |
---|
[93b4e6ef] | 61 | (the_tod->second >= TOD_SECONDS_PER_MINUTE) || |
---|
| 62 | (the_tod->minute >= TOD_MINUTES_PER_HOUR) || |
---|
| 63 | (the_tod->hour >= TOD_HOURS_PER_DAY) || |
---|
| 64 | (the_tod->month == 0) || |
---|
| 65 | (the_tod->month > TOD_MONTHS_PER_YEAR) || |
---|
| 66 | (the_tod->year < TOD_BASE_YEAR) || |
---|
| 67 | (the_tod->day == 0) ) |
---|
[484a769] | 68 | return false; |
---|
[93b4e6ef] | 69 | |
---|
| 70 | if ( (the_tod->year % 4) == 0 ) |
---|
| 71 | days_in_month = _TOD_Days_per_month[ 1 ][ the_tod->month ]; |
---|
| 72 | else |
---|
| 73 | days_in_month = _TOD_Days_per_month[ 0 ][ the_tod->month ]; |
---|
| 74 | |
---|
| 75 | if ( the_tod->day > days_in_month ) |
---|
[484a769] | 76 | return false; |
---|
[93b4e6ef] | 77 | |
---|
[484a769] | 78 | return true; |
---|
[93b4e6ef] | 79 | } |
---|