Changeset 465ac5e in mainline for uspace/app/date_cfg/date_cfg.c
- Timestamp:
- 2025-04-12T15:49:45Z (3 days ago)
- Children:
- 1cea9c0
- Parents:
- b8b031f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/date_cfg/date_cfg.c
rb8b031f r465ac5e 256 256 const char *date_str = ui_entry_get_text(date_cfg->date_entry); 257 257 const char *time_str = ui_entry_get_text(date_cfg->time_entry); 258 int day, month, year;258 int first_num, second_num, year; 259 259 int hour, min, sec; 260 260 261 if (sscanf(date_str, "%d/%d/%d", & day, &month, &year) != 3)261 if (sscanf(date_str, "%d/%d/%d", &first_num, &second_num, &year) != 3) 262 262 return EINVAL; 263 263 … … 265 265 return EINVAL; 266 266 267 if (day < 1 || day > 31 || month < 1 || month > 12 || year < 1900) 267 /* Determine format based on first number */ 268 if (first_num > 12) { 269 /* First number is day (DD/MM/YYYY format) */ 270 date_cfg->current_time.tm_mday = first_num; 271 date_cfg->current_time.tm_mon = second_num - 1; 272 } else if (second_num > 12) { 273 /* Second number is day (MM/DD/YYYY format) */ 274 date_cfg->current_time.tm_mon = first_num - 1; 275 date_cfg->current_time.tm_mday = second_num; 276 } else { 277 /* Ambiguous case - assume DD/MM/YYYY format */ 278 date_cfg->current_time.tm_mday = first_num; 279 date_cfg->current_time.tm_mon = second_num - 1; 280 } 281 282 if (date_cfg->current_time.tm_mday < 1 || date_cfg->current_time.tm_mday > 31 || 283 date_cfg->current_time.tm_mon < 0 || date_cfg->current_time.tm_mon > 11 || 284 year < 1900) 268 285 return EINVAL; 269 286 … … 271 288 return EINVAL; 272 289 273 date_cfg->current_time.tm_mday = day;274 date_cfg->current_time.tm_mon = month - 1;275 290 date_cfg->current_time.tm_year = year - 1900; 276 291 date_cfg->current_time.tm_hour = hour;
Note:
See TracChangeset
for help on using the changeset viewer.