1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** FileX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** System */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define FX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "fx_api.h" |
28 |
|
|
#include "fx_system.h" |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
/**************************************************************************/ |
32 |
|
|
/* */ |
33 |
|
|
/* FUNCTION RELEASE */ |
34 |
|
|
/* */ |
35 |
|
|
/* _fxe_system_date_set PORTABLE C */ |
36 |
|
|
/* 6.1 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* William E. Lamie, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function checks for errors in the set system date call. */ |
44 |
|
|
/* */ |
45 |
|
|
/* INPUT */ |
46 |
|
|
/* */ |
47 |
|
|
/* year Year (1980-2107) */ |
48 |
|
|
/* month Month (1-12) */ |
49 |
|
|
/* day Day (1-28/29/30/31) */ |
50 |
|
|
/* */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* FX_INVALID_YEAR Supplied year is invalid */ |
54 |
|
|
/* FX_INVALID_MONTH Supplied month is invalid */ |
55 |
|
|
/* FX_INVALID_DAY Supplied day is invalid */ |
56 |
|
|
/* status Actual completion status */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* _fx_system_date_set Actual system date set call */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLED BY */ |
63 |
|
|
/* */ |
64 |
|
|
/* Application Code */ |
65 |
|
|
/* */ |
66 |
|
|
/* RELEASE HISTORY */ |
67 |
|
|
/* */ |
68 |
|
|
/* DATE NAME DESCRIPTION */ |
69 |
|
|
/* */ |
70 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
71 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
72 |
|
|
/* resulting in version 6.1 */ |
73 |
|
|
/* */ |
74 |
|
|
/**************************************************************************/ |
75 |
|
32 |
UINT _fxe_system_date_set(UINT year, UINT month, UINT day) |
76 |
|
|
{ |
77 |
|
|
|
78 |
|
|
UINT status; |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
/* Check for invalid year. */ |
82 |
✓✓✓✓
|
32 |
if ((year < FX_BASE_YEAR) || (year > FX_MAXIMUM_YEAR)) |
83 |
|
|
{ |
84 |
|
2 |
return(FX_INVALID_YEAR); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
/* Check for invalid day. */ |
88 |
✓✓ |
30 |
if (day < 1) |
89 |
|
|
{ |
90 |
|
1 |
return(FX_INVALID_DAY); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/* Check for invalid day. */ |
94 |
✓✓✓✓ ✓✓✓✓ ✓✓✓✓ ✓ |
29 |
switch (month) |
95 |
|
|
{ |
96 |
|
|
|
97 |
|
2 |
case 1: |
98 |
|
|
{ |
99 |
|
|
|
100 |
|
|
/* Check for 31 days. */ |
101 |
✓✓ |
2 |
if (day > 31) |
102 |
|
|
{ |
103 |
|
1 |
return(FX_INVALID_DAY); |
104 |
|
|
} |
105 |
|
1 |
break; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
5 |
case 2: |
109 |
|
|
{ |
110 |
|
|
|
111 |
|
|
/* Check for leap year. */ |
112 |
✓✓ |
5 |
if ((year % 4) == 0) |
113 |
|
|
{ |
114 |
|
|
|
115 |
|
|
/* Leap year, February has 29 days. */ |
116 |
✓✓ |
3 |
if (day > 29) |
117 |
|
|
{ |
118 |
|
2 |
return(FX_INVALID_DAY); |
119 |
|
|
} |
120 |
|
|
} |
121 |
|
|
else |
122 |
|
|
{ |
123 |
|
|
|
124 |
|
|
/* Otherwise, non-leap year. February has |
125 |
|
|
28 days. */ |
126 |
✓✓ |
2 |
if (day > 28) |
127 |
|
|
{ |
128 |
|
1 |
return(FX_INVALID_DAY); |
129 |
|
|
} |
130 |
|
|
} |
131 |
|
2 |
break; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
2 |
case 3: |
135 |
|
|
{ |
136 |
|
|
|
137 |
|
|
/* Check for 31 days. */ |
138 |
✓✓ |
2 |
if (day > 31) |
139 |
|
|
{ |
140 |
|
1 |
return(FX_INVALID_DAY); |
141 |
|
|
} |
142 |
|
1 |
break; |
143 |
|
|
} |
144 |
|
|
|
145 |
|
2 |
case 4: |
146 |
|
|
{ |
147 |
|
|
|
148 |
|
|
/* Check for 30 days. */ |
149 |
✓✓ |
2 |
if (day > 30) |
150 |
|
|
{ |
151 |
|
1 |
return(FX_INVALID_DAY); |
152 |
|
|
} |
153 |
|
1 |
break; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
2 |
case 5: |
157 |
|
|
{ |
158 |
|
|
|
159 |
|
|
/* Check for 31 days. */ |
160 |
✓✓ |
2 |
if (day > 31) |
161 |
|
|
{ |
162 |
|
1 |
return(FX_INVALID_DAY); |
163 |
|
|
} |
164 |
|
1 |
break; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
2 |
case 6: |
168 |
|
|
{ |
169 |
|
|
|
170 |
|
|
/* Check for 30 days. */ |
171 |
✓✓ |
2 |
if (day > 30) |
172 |
|
|
{ |
173 |
|
1 |
return(FX_INVALID_DAY); |
174 |
|
|
} |
175 |
|
1 |
break; |
176 |
|
|
} |
177 |
|
|
|
178 |
|
2 |
case 7: |
179 |
|
|
{ |
180 |
|
|
|
181 |
|
|
/* Check for 31 days. */ |
182 |
✓✓ |
2 |
if (day > 31) |
183 |
|
|
{ |
184 |
|
1 |
return(FX_INVALID_DAY); |
185 |
|
|
} |
186 |
|
1 |
break; |
187 |
|
|
} |
188 |
|
|
|
189 |
|
2 |
case 8: |
190 |
|
|
{ |
191 |
|
|
|
192 |
|
|
/* Check for 31 days. */ |
193 |
✓✓ |
2 |
if (day > 31) |
194 |
|
|
{ |
195 |
|
1 |
return(FX_INVALID_DAY); |
196 |
|
|
} |
197 |
|
1 |
break; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
2 |
case 9: |
201 |
|
|
{ |
202 |
|
|
|
203 |
|
|
/* Check for 30 days. */ |
204 |
✓✓ |
2 |
if (day > 30) |
205 |
|
|
{ |
206 |
|
1 |
return(FX_INVALID_DAY); |
207 |
|
|
} |
208 |
|
1 |
break; |
209 |
|
|
} |
210 |
|
|
|
211 |
|
2 |
case 10: |
212 |
|
|
{ |
213 |
|
|
|
214 |
|
|
/* Check for 31 days. */ |
215 |
✓✓ |
2 |
if (day > 31) |
216 |
|
|
{ |
217 |
|
1 |
return(FX_INVALID_DAY); |
218 |
|
|
} |
219 |
|
1 |
break; |
220 |
|
|
} |
221 |
|
|
|
222 |
|
2 |
case 11: |
223 |
|
|
{ |
224 |
|
|
|
225 |
|
|
/* Check for 30 days. */ |
226 |
✓✓ |
2 |
if (day > 30) |
227 |
|
|
{ |
228 |
|
1 |
return(FX_INVALID_DAY); |
229 |
|
|
} |
230 |
|
1 |
break; |
231 |
|
|
} |
232 |
|
|
|
233 |
|
3 |
case 12: |
234 |
|
|
{ |
235 |
|
|
|
236 |
|
|
/* Check for 31 days. */ |
237 |
✓✓ |
3 |
if (day > 31) |
238 |
|
|
{ |
239 |
|
1 |
return(FX_INVALID_DAY); |
240 |
|
|
} |
241 |
|
2 |
break; |
242 |
|
|
} |
243 |
|
|
|
244 |
|
1 |
default: |
245 |
|
|
|
246 |
|
|
/* Invalid month. */ |
247 |
|
1 |
return(FX_INVALID_MONTH); |
248 |
|
|
} |
249 |
|
|
|
250 |
|
|
/* Call actual system date set service. */ |
251 |
|
14 |
status = _fx_system_date_set(year, month, day); |
252 |
|
|
|
253 |
|
|
/* Return status. */ |
254 |
|
14 |
return(status); |
255 |
|
|
} |
256 |
|
|
|