00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <stdio.h>
00037 #include "Basic.h"
00038 #include "time_conversion.h"
00039 #include "constants.h"
00040
00041
00042 int init_suite_TIMECONV(void)
00043 {
00044 return 0;
00045 }
00046
00047 int clean_suite_TIMECONV(void)
00048 {
00049 return 0;
00050 }
00051
00052
00053 void test_TIMECONV_GetJulianDateFromGPSTime(void)
00054 {
00055 unsigned short gpsWeek;
00056 double gpsTow;
00057 unsigned char utcOffset;
00058 double julianDate;
00059 BOOL result;
00060
00061 const double julian_date_start_of_gps_time = (2444244.5);
00062
00063 gpsWeek = 0;
00064 gpsTow = 0.0;
00065 utcOffset = 0;
00066 result = TIMECONV_GetJulianDateFromGPSTime(
00067 gpsWeek,
00068 gpsTow,
00069 utcOffset,
00070 &julianDate );
00071 CU_ASSERT_FATAL( result );
00072 CU_ASSERT_DOUBLE_EQUAL( julianDate, julian_date_start_of_gps_time, 0.0001 );
00073
00074 gpsWeek = 1;
00075 gpsTow = 0.0;
00076 utcOffset = 0;
00077 result = TIMECONV_GetJulianDateFromGPSTime(
00078 gpsWeek,
00079 gpsTow,
00080 utcOffset,
00081 &julianDate );
00082 CU_ASSERT_FATAL( result );
00083 CU_ASSERT_DOUBLE_EQUAL( julianDate - 7, julian_date_start_of_gps_time, 0.0001 );
00084
00085 gpsWeek = 1024;
00086 gpsTow = 302400.0;
00087 utcOffset = 0;
00088 result = TIMECONV_GetJulianDateFromGPSTime(
00089 gpsWeek,
00090 gpsTow,
00091 utcOffset,
00092 &julianDate );
00093 CU_ASSERT_FATAL( result );
00094 CU_ASSERT_DOUBLE_EQUAL( julianDate - 7*1024 - 3.5, julian_date_start_of_gps_time, 0.0001 );
00095 }
00096
00097
00098 void test_TIMECONV_GetJulianDateFromUTCTime(void)
00099 {
00100 unsigned short utc_year;
00101 unsigned char utc_month;
00102 unsigned char utc_day;
00103 unsigned char utc_hour;
00104 unsigned char utc_minute;
00105 float utc_seconds;
00106 double julian_date;
00107 BOOL result;
00108
00109 const double julian_date_start_of_gps_time = (2444244.5);
00110
00111 utc_year = 1980;
00112 utc_month = 1;
00113 utc_day = 6;
00114 utc_hour = 0;
00115 utc_minute = 0;
00116 utc_seconds = 0.0;
00117
00118 result = TIMECONV_GetJulianDateFromUTCTime(
00119 utc_year,
00120 utc_month,
00121 utc_day,
00122 utc_hour,
00123 utc_minute,
00124 utc_seconds,
00125 &julian_date );
00126 CU_ASSERT_FATAL( result );
00127
00128 CU_ASSERT_DOUBLE_EQUAL( julian_date, julian_date_start_of_gps_time, 0.0001 );
00129
00130 utc_year = 1981;
00131 result = TIMECONV_GetJulianDateFromUTCTime(
00132 utc_year,
00133 utc_month,
00134 utc_day,
00135 utc_hour,
00136 utc_minute,
00137 utc_seconds,
00138 &julian_date );
00139 CU_ASSERT_FATAL( result );
00140 CU_ASSERT_DOUBLE_EQUAL( julian_date - 366, julian_date_start_of_gps_time, 0.0001 );
00141 }
00142
00143 void test_TIMECONV_GetGPSTimeFromJulianDate(void)
00144 {
00145 double julian_date;
00146 unsigned char utc_offset;
00147 unsigned short gps_week;
00148 double gps_tow;
00149 BOOL result;
00150
00151 const double julian_date_start_of_gps_time = (2444244.5);
00152
00153 julian_date = julian_date_start_of_gps_time;
00154 utc_offset = 0;
00155 result = TIMECONV_GetGPSTimeFromJulianDate(
00156 julian_date,
00157 utc_offset,
00158 &gps_week,
00159 &gps_tow );
00160 CU_ASSERT_FATAL( result );
00161 CU_ASSERT( gps_week == 0 );
00162 CU_ASSERT_DOUBLE_EQUAL( gps_tow, 0.0, 1e-08 );
00163
00164 julian_date = julian_date_start_of_gps_time + 7*1024 + 3.5;
00165 utc_offset = 13;
00166 result = TIMECONV_GetGPSTimeFromJulianDate(
00167 julian_date,
00168 utc_offset,
00169 &gps_week,
00170 &gps_tow );
00171 CU_ASSERT_FATAL( result );
00172 CU_ASSERT( gps_week == 1024 );
00173 CU_ASSERT_DOUBLE_EQUAL( gps_tow, 302413.0, 1e-08 );
00174 }
00175
00176 void test_TIMECONV_GetUTCTimeFromJulianDate(void)
00177 {
00178 unsigned short utc_year;
00179 unsigned char utc_month;
00180 unsigned char utc_day;
00181 unsigned char utc_hour;
00182 unsigned char utc_minute;
00183 float utc_seconds;
00184 double julian_date;
00185 BOOL result;
00186
00187 const double julian_date_start_of_gps_time = (2444244.5);
00188
00189 julian_date = julian_date_start_of_gps_time;
00190
00191 result = TIMECONV_GetUTCTimeFromJulianDate(
00192 julian_date,
00193 &utc_year,
00194 &utc_month,
00195 &utc_day,
00196 &utc_hour,
00197 &utc_minute,
00198 &utc_seconds );
00199 CU_ASSERT_FATAL( result );
00200 CU_ASSERT( utc_year == 1980 );
00201 CU_ASSERT( utc_month == 1 );
00202 CU_ASSERT( utc_day == 6 );
00203 CU_ASSERT( utc_hour == 0 );
00204 CU_ASSERT( utc_minute == 0 );
00205 CU_ASSERT_DOUBLE_EQUAL( utc_seconds, 0.0, 1e-08 );
00206
00207
00208 julian_date = julian_date_start_of_gps_time + 366;
00209 result = TIMECONV_GetUTCTimeFromJulianDate(
00210 julian_date,
00211 &utc_year,
00212 &utc_month,
00213 &utc_day,
00214 &utc_hour,
00215 &utc_minute,
00216 &utc_seconds );
00217 CU_ASSERT_FATAL( result );
00218 CU_ASSERT( utc_year == 1981 );
00219 CU_ASSERT( utc_month == 1 );
00220 CU_ASSERT( utc_day == 6 );
00221 CU_ASSERT( utc_hour == 0 );
00222 CU_ASSERT( utc_minute == 0 );
00223 CU_ASSERT_DOUBLE_EQUAL( utc_seconds, 0.0, 1e-08 );
00224 }
00225
00226
00227 void test_TIMECONV_GetGPSTimeFromUTCTime(void)
00228 {
00229 unsigned short utc_year;
00230 unsigned char utc_month;
00231 unsigned char utc_day;
00232 unsigned char utc_hour;
00233 unsigned char utc_minute;
00234 float utc_seconds;
00235 unsigned short gps_week;
00236 double gps_tow;
00237 BOOL result;
00238
00239 utc_year = 1980;
00240 utc_month = 1;
00241 utc_day = 6;
00242 utc_hour = 0;
00243 utc_minute = 0;
00244 utc_seconds = 0.0;
00245 result = TIMECONV_GetGPSTimeFromUTCTime(
00246 utc_year,
00247 utc_month,
00248 utc_day,
00249 utc_hour,
00250 utc_minute,
00251 utc_seconds,
00252 &gps_week,
00253 &gps_tow );
00254 CU_ASSERT_FATAL( result );
00255 CU_ASSERT( gps_week == 0 );
00256 CU_ASSERT_DOUBLE_EQUAL( gps_tow, 0.0, 1e-08 );
00257
00258 utc_year = 1999;
00259 utc_month = 8;
00260 utc_day = 22;
00261 utc_hour = 0;
00262 utc_minute = 0;
00263 utc_seconds = 0.0;
00264 result = TIMECONV_GetGPSTimeFromUTCTime(
00265 utc_year,
00266 utc_month,
00267 utc_day,
00268 utc_hour,
00269 utc_minute,
00270 utc_seconds,
00271 &gps_week,
00272 &gps_tow );
00273 CU_ASSERT_FATAL( result );
00274 CU_ASSERT( gps_week == 1024 );
00275 CU_ASSERT_DOUBLE_EQUAL( gps_tow, 13.0, 1e-08 );
00276 }
00277
00278 void test_TIMECONV_GetUTCTimeFromGPSTime(void)
00279 {
00280 unsigned short utc_year;
00281 unsigned char utc_month;
00282 unsigned char utc_day;
00283 unsigned char utc_hour;
00284 unsigned char utc_minute;
00285 float utc_seconds;
00286 unsigned short gps_week;
00287 double gps_tow;
00288 BOOL result;
00289
00290 gps_week = 0;
00291 gps_tow = 0.0;
00292 result = TIMECONV_GetUTCTimeFromGPSTime(
00293 gps_week,
00294 gps_tow,
00295 &utc_year,
00296 &utc_month,
00297 &utc_day,
00298 &utc_hour,
00299 &utc_minute,
00300 &utc_seconds );
00301 CU_ASSERT_FATAL( result );
00302 CU_ASSERT( utc_year == 1980 );
00303 CU_ASSERT( utc_month == 1 );
00304 CU_ASSERT( utc_day == 6 );
00305 CU_ASSERT( utc_hour == 0 );
00306 CU_ASSERT( utc_minute == 0 );
00307 CU_ASSERT_DOUBLE_EQUAL( utc_seconds, 0.0, 1e-08 );
00308
00309 gps_week = 1024;
00310 gps_tow = 13.0;
00311 result = TIMECONV_GetUTCTimeFromGPSTime(
00312 gps_week,
00313 gps_tow,
00314 &utc_year,
00315 &utc_month,
00316 &utc_day,
00317 &utc_hour,
00318 &utc_minute,
00319 &utc_seconds );
00320 CU_ASSERT_FATAL( result );
00321 CU_ASSERT( utc_year == 1999 );
00322 CU_ASSERT( utc_month == 8 );
00323 CU_ASSERT( utc_day == 22 );
00324 CU_ASSERT( utc_hour == 0 );
00325 CU_ASSERT( utc_minute == 0 );
00326 CU_ASSERT_DOUBLE_EQUAL( utc_seconds, 0.0, 1e-08 );
00327 }
00328
00329
00330 void test_TIMECONV_DetermineUTCOffset(void)
00331 {
00332 double julian_date;
00333 unsigned char utc_offset;
00334 BOOL result;
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 julian_date = 2444244.5000 + 1;
00352 result = TIMECONV_DetermineUTCOffset(
00353 julian_date,
00354 &utc_offset );
00355 CU_ASSERT_FATAL( result );
00356 CU_ASSERT( utc_offset == 0 );
00357
00358 julian_date = 2444786.5 + 1;
00359 result = TIMECONV_DetermineUTCOffset(
00360 julian_date,
00361 &utc_offset );
00362 CU_ASSERT_FATAL( result );
00363 CU_ASSERT( utc_offset == 1 );
00364
00365 julian_date = 2445151.5 + 1;
00366 result = TIMECONV_DetermineUTCOffset(
00367 julian_date,
00368 &utc_offset );
00369 CU_ASSERT_FATAL( result );
00370 CU_ASSERT( utc_offset == 2 );
00371
00372 julian_date = 2445516.5 + 1;
00373 result = TIMECONV_DetermineUTCOffset(
00374 julian_date,
00375 &utc_offset );
00376 CU_ASSERT_FATAL( result );
00377 CU_ASSERT( utc_offset == 3 );
00378
00379 julian_date = 2446247.5 + 1;
00380 result = TIMECONV_DetermineUTCOffset(
00381 julian_date,
00382 &utc_offset );
00383 CU_ASSERT_FATAL( result );
00384 CU_ASSERT( utc_offset == 4 );
00385
00386 julian_date = 2447161.5 + 1;
00387 result = TIMECONV_DetermineUTCOffset(
00388 julian_date,
00389 &utc_offset );
00390 CU_ASSERT_FATAL( result );
00391 CU_ASSERT( utc_offset == 5 );
00392
00393 julian_date = 2447892.5 + 1;
00394 result = TIMECONV_DetermineUTCOffset(
00395 julian_date,
00396 &utc_offset );
00397 CU_ASSERT_FATAL( result );
00398 CU_ASSERT( utc_offset == 6 );
00399
00400 julian_date = 2448257.5 + 1;
00401 result = TIMECONV_DetermineUTCOffset(
00402 julian_date,
00403 &utc_offset );
00404 CU_ASSERT_FATAL( result );
00405 CU_ASSERT( utc_offset == 7 );
00406
00407 julian_date = 2448804.5 + 1;
00408 result = TIMECONV_DetermineUTCOffset(
00409 julian_date,
00410 &utc_offset );
00411 CU_ASSERT_FATAL( result );
00412 CU_ASSERT( utc_offset == 8 );
00413
00414 julian_date = 2449169.5 + 1;
00415 result = TIMECONV_DetermineUTCOffset(
00416 julian_date,
00417 &utc_offset );
00418 CU_ASSERT_FATAL( result );
00419 CU_ASSERT( utc_offset == 9 );
00420
00421 julian_date = 2449534.5 + 1;
00422 result = TIMECONV_DetermineUTCOffset(
00423 julian_date,
00424 &utc_offset );
00425 CU_ASSERT_FATAL( result );
00426 CU_ASSERT( utc_offset == 10 );
00427
00428 julian_date = 2450083.5 + 1;
00429 result = TIMECONV_DetermineUTCOffset(
00430 julian_date,
00431 &utc_offset );
00432 CU_ASSERT_FATAL( result );
00433 CU_ASSERT( utc_offset == 11 );
00434
00435 julian_date = 2450630.5 + 1;
00436 result = TIMECONV_DetermineUTCOffset(
00437 julian_date,
00438 &utc_offset );
00439 CU_ASSERT_FATAL( result );
00440 CU_ASSERT( utc_offset == 12 );
00441
00442 julian_date = 2451179.5 + 1;
00443 result = TIMECONV_DetermineUTCOffset(
00444 julian_date,
00445 &utc_offset );
00446 CU_ASSERT_FATAL( result );
00447 CU_ASSERT( utc_offset == 13 );
00448
00449 }
00450
00451
00452 void test_TIMECONV_GetNumberOfDaysInMonth(void)
00453 {
00454 unsigned char days_in_month;
00455 BOOL result;
00456
00457 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 1, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00458 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 2, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 29 );
00459 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 3, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00460 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 4, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 30 );
00461 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 5, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00462 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 6, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 30 );
00463 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 7, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00464 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 8, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00465 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 9, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 30 );
00466 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 10, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00467 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 11, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 30 );
00468 result = TIMECONV_GetNumberOfDaysInMonth( 1980, 12, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00469
00470 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 1, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00471 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 2, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 28 );
00472 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 3, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00473 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 4, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 30 );
00474 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 5, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00475 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 6, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 30 );
00476 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 7, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00477 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 8, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00478 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 9, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 30 );
00479 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 10, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00480 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 11, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 30 );
00481 result = TIMECONV_GetNumberOfDaysInMonth( 2006, 12, &days_in_month ); CU_ASSERT_FATAL( result ); CU_ASSERT( days_in_month == 31 );
00482
00483 }
00484
00485 void test_TIMECONV_IsALeapYear(void)
00486 {
00487 CU_ASSERT( TIMECONV_IsALeapYear(1980) == 1 );
00488 CU_ASSERT( TIMECONV_IsALeapYear(1981) == 0 );
00489 CU_ASSERT( TIMECONV_IsALeapYear(2000) == 1 );
00490 CU_ASSERT( TIMECONV_IsALeapYear(2006) == 0 );
00491 }
00492
00493
00494 void test_TIMECONV_GetDayOfYear(void)
00495 {
00496 unsigned short dayofyear;
00497 BOOL result;
00498
00499 result = TIMECONV_GetDayOfYear(
00500 1980,
00501 12,
00502 31,
00503 &dayofyear );
00504 CU_ASSERT_FATAL( result );
00505 CU_ASSERT( dayofyear == 366 );
00506
00507 result = TIMECONV_GetDayOfYear(
00508 2006,
00509 12,
00510 31,
00511 &dayofyear );
00512 CU_ASSERT_FATAL( result );
00513 CU_ASSERT( dayofyear == 365 );
00514 }
00515
00516
00517 void test_TIMECONV_GetGPSTimeFromYearAndDayOfYear(void)
00518 {
00519 BOOL result = 0;
00520
00521 unsigned short year = 1999;
00522 unsigned short dayofyear = 31;
00523 unsigned short gps_week = 0;
00524 double gps_tow = 0;
00525
00526 result = TIMECONV_GetGPSTimeFromYearAndDayOfYear(
00527 year,
00528 dayofyear,
00529 &gps_week,
00530 &gps_tow );
00531
00532 CU_ASSERT( gps_week == 995 ) ;
00533 CU_ASSERT_DOUBLE_EQUAL( gps_tow, 0, 1e-03 ) ;
00534
00535 result = TIMECONV_GetGPSTimeFromYearAndDayOfYear(
00536 2000,
00537 60,
00538 &gps_week,
00539 &gps_tow );
00540
00541 CU_ASSERT( gps_week == 1051 ) ;
00542 CU_ASSERT_DOUBLE_EQUAL( gps_tow, 172800, 1e-03 ) ;
00543 }
00544
00545