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 /**************************************************************************/
_fxe_system_date_set(UINT year,UINT month,UINT day)75 UINT _fxe_system_date_set(UINT year, UINT month, UINT day)
76 {
77
78 UINT status;
79
80
81 /* Check for invalid year. */
82 if ((year < FX_BASE_YEAR) || (year > FX_MAXIMUM_YEAR))
83 {
84 return(FX_INVALID_YEAR);
85 }
86
87 /* Check for invalid day. */
88 if (day < 1)
89 {
90 return(FX_INVALID_DAY);
91 }
92
93 /* Check for invalid day. */
94 switch (month)
95 {
96
97 case 1:
98 {
99
100 /* Check for 31 days. */
101 if (day > 31)
102 {
103 return(FX_INVALID_DAY);
104 }
105 break;
106 }
107
108 case 2:
109 {
110
111 /* Check for leap year. */
112 if ((year % 4) == 0)
113 {
114
115 /* Leap year, February has 29 days. */
116 if (day > 29)
117 {
118 return(FX_INVALID_DAY);
119 }
120 }
121 else
122 {
123
124 /* Otherwise, non-leap year. February has
125 28 days. */
126 if (day > 28)
127 {
128 return(FX_INVALID_DAY);
129 }
130 }
131 break;
132 }
133
134 case 3:
135 {
136
137 /* Check for 31 days. */
138 if (day > 31)
139 {
140 return(FX_INVALID_DAY);
141 }
142 break;
143 }
144
145 case 4:
146 {
147
148 /* Check for 30 days. */
149 if (day > 30)
150 {
151 return(FX_INVALID_DAY);
152 }
153 break;
154 }
155
156 case 5:
157 {
158
159 /* Check for 31 days. */
160 if (day > 31)
161 {
162 return(FX_INVALID_DAY);
163 }
164 break;
165 }
166
167 case 6:
168 {
169
170 /* Check for 30 days. */
171 if (day > 30)
172 {
173 return(FX_INVALID_DAY);
174 }
175 break;
176 }
177
178 case 7:
179 {
180
181 /* Check for 31 days. */
182 if (day > 31)
183 {
184 return(FX_INVALID_DAY);
185 }
186 break;
187 }
188
189 case 8:
190 {
191
192 /* Check for 31 days. */
193 if (day > 31)
194 {
195 return(FX_INVALID_DAY);
196 }
197 break;
198 }
199
200 case 9:
201 {
202
203 /* Check for 30 days. */
204 if (day > 30)
205 {
206 return(FX_INVALID_DAY);
207 }
208 break;
209 }
210
211 case 10:
212 {
213
214 /* Check for 31 days. */
215 if (day > 31)
216 {
217 return(FX_INVALID_DAY);
218 }
219 break;
220 }
221
222 case 11:
223 {
224
225 /* Check for 30 days. */
226 if (day > 30)
227 {
228 return(FX_INVALID_DAY);
229 }
230 break;
231 }
232
233 case 12:
234 {
235
236 /* Check for 31 days. */
237 if (day > 31)
238 {
239 return(FX_INVALID_DAY);
240 }
241 break;
242 }
243
244 default:
245
246 /* Invalid month. */
247 return(FX_INVALID_MONTH);
248 }
249
250 /* Call actual system date set service. */
251 status = _fx_system_date_set(year, month, day);
252
253 /* Return status. */
254 return(status);
255 }
256
257