Changeset 465ac5e in mainline


Ignore:
Timestamp:
2025-04-12T15:49:45Z (45 hours ago)
Author:
Wayne Thornton <wmthornton-dev@…>
Children:
1cea9c0
Parents:
b8b031f
Message:

Added international date format support

MM:DD:YYYY is now supported alongside current DD:MM:YYYY format.
Updated 'date' and 'date_cfg' to support changes.

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    rb8b031f r465ac5e  
    99tools/xcw/demo/viewer
    1010/.cache
     11/PKG
     12/downloads
     13/amd64-helenos
     14.cursorignore
  • uspace/app/date/date.c

    rb8b031f r465ac5e  
    11/*
     2 * Copyright (c) 2025 Wayne Michael Thornton (WMT) <wmthornton-dev@outlook.com>
    23 * Copyright (c) 2012 Maurizio Lombardi
    34 * All rights reserved.
     
    195196
    196197/** Read the day, month and year from a string
    197  *  with the following format: DD/MM/YYYY
     198 *  with the following format: DD/MM/YYYY or MM/DD/YYYY
    198199 */
    199200static errno_t
     
    202203        errno_t rc;
    203204        uint32_t tmp;
     205        uint32_t first_num;
     206        uint32_t second_num;
    204207
    205208        if (str_size(wdate) != 10) /* str_size("DD/MM/YYYY") == 10 */
     
    211214        }
    212215
    213         rc = str_uint32_t(&wdate[0], NULL, 10, false, &tmp);
    214         if (rc != EOK)
    215                 return rc;
    216 
    217         t->tm_mday = tmp;
    218 
    219         rc = str_uint32_t(&wdate[3], NULL, 10, false, &tmp);
    220         if (rc != EOK)
    221                 return rc;
    222 
    223         t->tm_mon = tmp - 1;
     216        /* Parse first number */
     217        rc = str_uint32_t(&wdate[0], NULL, 10, false, &first_num);
     218        if (rc != EOK)
     219                return rc;
     220
     221        /* Parse second number */
     222        rc = str_uint32_t(&wdate[3], NULL, 10, false, &second_num);
     223        if (rc != EOK)
     224                return rc;
     225
     226        /* Determine format based on first number */
     227        if (first_num > 12) {
     228                /* First number is day (DD/MM/YYYY format) */
     229                t->tm_mday = first_num;
     230                t->tm_mon = second_num - 1;
     231        } else if (second_num > 12) {
     232                /* Second number is day (MM/DD/YYYY format) */
     233                t->tm_mon = first_num - 1;
     234                t->tm_mday = second_num;
     235        } else {
     236                /* Ambiguous case - assume DD/MM/YYYY format */
     237                t->tm_mday = first_num;
     238                t->tm_mon = second_num - 1;
     239        }
    224240
    225241        rc = str_uint32_t(&wdate[6], NULL, 10, false, &tmp);
     242        if (rc != EOK)
     243                return rc;
     244
    226245        t->tm_year = tmp - 1900;
    227246
    228         return rc;
     247        return EOK;
    229248}
    230249
     
    331350usage(void)
    332351{
    333         printf("Usage: date [-d DD/MM/YYYY] [-t HH:MM[:SS]]\n");
    334         printf("       -d   Change the current date\n");
     352        printf("Usage: date [-d DD/MM/YYYY|MM/DD/YYYY] [-t HH:MM[:SS]]\n");
     353        printf("       -d   Change the current date (supports both DD/MM/YYYY and MM/DD/YYYY formats)\n");
    335354        printf("       -t   Change the current time\n");
    336355        printf("       -h   Display this information\n");
  • uspace/app/date_cfg/date_cfg.c

    rb8b031f r465ac5e  
    256256        const char *date_str = ui_entry_get_text(date_cfg->date_entry);
    257257        const char *time_str = ui_entry_get_text(date_cfg->time_entry);
    258         int day, month, year;
     258        int first_num, second_num, year;
    259259        int hour, min, sec;
    260260
    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)
    262262                return EINVAL;
    263263
     
    265265                return EINVAL;
    266266
    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)
    268285                return EINVAL;
    269286
     
    271288                return EINVAL;
    272289
    273         date_cfg->current_time.tm_mday = day;
    274         date_cfg->current_time.tm_mon = month - 1;
    275290        date_cfg->current_time.tm_year = year - 1900;
    276291        date_cfg->current_time.tm_hour = hour;
Note: See TracChangeset for help on using the changeset viewer.