1 /*
2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
3 * Created by: majid.awad REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license. For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7 *
8 *
9 * The names in the broken-down tm structure should correspond to its values.
10 *
11 */
12
13 #include <stdio.h>
14 #include <time.h>
15 #include <posixtest.h>
16
main(void)17 int main(void)
18 {
19 struct tm *tm_ptr;
20 time_t the_time;
21 int total_years;
22
23 (void)time(&the_time);
24 tm_ptr = gmtime(&the_time);
25 printf("Raw time is %ld \n", the_time);
26 printf("gmtime gives:\n");
27
28 /* Checking the seconds */
29 if ((tm_ptr->tm_sec >= 0) && (tm_ptr->tm_sec < 60)) {
30 printf("sec %02d\n", tm_ptr->tm_sec);
31 } else {
32 puts("Test FAILED: seconds");
33 return PTS_FAIL;
34 }
35
36 /* Checking the Minutes */
37 if ((tm_ptr->tm_min >= 0) && (tm_ptr->tm_min <= 59)) {
38 printf("min %02d\n", tm_ptr->tm_min);
39 } else {
40 puts("Test FAILED: minutes");
41 return PTS_FAIL;
42 }
43
44 /* Checking the Hour */
45 if ((tm_ptr->tm_hour >= 0) && (tm_ptr->tm_hour <= 23)) {
46 printf("hour %02d\n", tm_ptr->tm_hour);
47 } else {
48 puts("Test FAILED: hour");
49 return PTS_FAIL;
50 }
51
52 /* Checking the Month Day */
53 if ((tm_ptr->tm_mday >= 1) && (tm_ptr->tm_mday <= 31)) {
54 printf("mday %02d\n", tm_ptr->tm_mday);
55 } else {
56 puts("Test FAILED: mday");
57 return PTS_FAIL;
58 }
59
60 /* Checking the Month */
61 if ((tm_ptr->tm_mon >= 0) && (tm_ptr->tm_mon <= 11)) {
62 printf("mon %02d\n", tm_ptr->tm_mon);
63 } else {
64 puts("Test FAILED: mon");
65 return PTS_FAIL;
66 }
67
68 /* Checking the Year */
69 total_years = (tm_ptr->tm_year + 1900);
70 if (total_years >= 1900) {
71 printf("year %d\n", total_years);
72 } else {
73 printf("year %d\n", total_years);
74 puts("Test FAILED: year");
75 return PTS_FAIL;
76 }
77
78 /* Checking the Day of week */
79 if ((tm_ptr->tm_wday >= 0) && (tm_ptr->tm_wday <= 6)) {
80 printf("wday %02d\n", tm_ptr->tm_wday);
81 } else {
82 puts("Test FAILED: wday");
83 return PTS_FAIL;
84 }
85
86 /* Checking the Day in year */
87 if ((tm_ptr->tm_yday >= 0) && (tm_ptr->tm_yday <= 365)) {
88 printf("yday %02d\n", tm_ptr->tm_yday);
89 } else {
90 puts("Test FAILED: yday");
91 return PTS_FAIL;
92 }
93
94 /* Checking the DTS */
95 if ((tm_ptr->tm_isdst >= -1) && (tm_ptr->tm_isdst <= 1)) {
96 printf("isdst %02d\n", tm_ptr->tm_isdst);
97 } else {
98 puts("Test FAILED: isdst");
99 return PTS_FAIL;
100 }
101
102 puts("Test PASSED");
103 return PTS_PASS;
104 }
105