diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 863702d65..06e589eb4 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -4860,20 +4860,106 @@ int util_parse_time (const char *datetime, struct timeval *tv); Arguments: -* _date_: date/time +* _date_: date/time (see supported formats below) * _tv_: parsed date/time ("timeval" structure) +Supported date/time format (supposing the current time is `2025-08-30 21:04:55` +(Europe/Paris), so with timezone offset `+02:00`, UTC time being `19:04:55`): + +[width="70%",cols="5,6m",options="header"] +|=== +| Format | Examples + +| Date (midnight) +| 2025-08-30 + +| ISO 8601, date + local time +| 2025-08-30T21:04:55 + + 2025-08-30T21:04:55.123456 + +| ISO 8601, date + local time + offset +| 2025-08-30T16:04:55-03 + + 2025-08-30T16:04:55-0300 + + 2025-08-30T21:04:55+0200 + + 2025-08-30T21:04:55+02:00 + + 2025-08-30T21:04:55.123456+0200 + +| ISO 8601, date + UTC time +| 2025-08-30T19:04:55Z + + 2025-08-30T19:04:55.123456Z + +| RFC 3339, date + local time +| 2025-08-30 21:04:55 + + 2025-08-30 21:04:55.123456 + +| RFC 3339, date + local time + offset +| 2025-08-30 16:04:55-03 + + 2025-08-30 16:04:55-0300 + + 2025-08-30 21:04:55+0200 + + 2025-08-30 21:04:55 +0200 + + 2025-08-30 21:04:55+02:00 + + 2025-08-30 21:04:55 +02:00 + + 2025-08-30 21:04:55.123456+0200 + + 2025-08-30 21:04:55.123456 +02:00 + +| RFC 3339, date + UTC time +| 2025-08-30 19:04:55Z + + 2025-08-30 19:04:55.123456Z + +| Local time +| 21:04:55 + + 21:04:55.123456 + +| Local time + offset +| 16:04:55-03 + + 16:04:55-0300 + + 21:04:55+0200 + + 21:04:55 +0200 + + 21:04:55+02:00 + + 21:04:55 +02:00 + + 21:04:55.123456+0200 + + 21:04:55.123456 +02:00 + +| UTC time +| 19:04:55Z + + 19:04:55.123456Z + +| Timestamp date +| 1756580695 + + 1756580695.123456 + + 1756580695,123456 +|=== + +Notes: + +* For ISO 8601, the separator between date and time is `T` (upper case) or `t` (lower case). +* For UTC time, the final char is `Z` (upper case) or `z` (lower case). +* The timezone offset format is one of: +** `++[+/-]hh:mm++` (hours and minutes) +** `++[+/-]hhmm++` (hours and minutes) +** `++[+/-]hh++` (hours). +* Precision after seconds can be from one-tenth of second (1 digit, for example + `21:04:55.1`) to one microsecond (6 digits, for example `21:04:55.123456`). + + A dot (`.`) or comma (`,`) can separate seconds from the other digits. + Return value: * 1 if OK, 0 if error -C example: +C examples: [source,c] ---- struct timeval tv; -weechat_util_parse_time ("2023-12-25T10:29:09.456789Z", &tv); /* == 1 */ -/* result: tv.tv_sec == 1703500149, tv.tv_usec = 456789 */ + +weechat_util_parse_time ("2025-08-30T19:04:55.123456Z", &tv); /* == 1 */ +/* result: tv.tv_sec == 1756580695, tv.tv_usec = 123456 */ + +weechat_util_parse_time ("2025-08-30 21:04:55.123456 +02:00", &tv); /* == 1 */ +/* same result */ + +weechat_util_parse_time ("21:04:55.123456", &tv); /* == 1 */ +/* same result */ ---- [NOTE] diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index 85386d884..fb8cbee4b 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -4941,20 +4941,108 @@ int util_parse_time (const char *datetime, struct timeval *tv); Paramètres : -* _date_ : date/heure +* _date_ : date/heure (voir les formats supportés ci-dessous) * _tv_: date/heure analysée (structure "timeval") +Les formats supportés pour la date/heure (en supposant que l'heure courante est +`2025-08-30 21:04:55` (Europe/Paris), donc avec le décalage horaire `+02:00`, +l'heure UTC étant `19:04:55`) : + +[width="70%",cols="5,6m",options="header"] +|=== +| Format | Exemples + +| Date (minuit) +| 2025-08-30 + +| ISO 8601, date + heure locale +| 2025-08-30T21:04:55 + + 2025-08-30T21:04:55.123456 + +| ISO 8601, date + heure locale + décalage horaire +| 2025-08-30T16:04:55-03 + + 2025-08-30T16:04:55-0300 + + 2025-08-30T21:04:55+0200 + + 2025-08-30T21:04:55+02:00 + + 2025-08-30T21:04:55.123456+0200 + +| ISO 8601, date + heure UTC +| 2025-08-30T19:04:55Z + + 2025-08-30T19:04:55.123456Z + +| RFC 3339, date + heure locale +| 2025-08-30 21:04:55 + + 2025-08-30 21:04:55.123456 + +| RFC 3339, date + heure locale + décalage horaire +| 2025-08-30 16:04:55-03 + + 2025-08-30 16:04:55-0300 + + 2025-08-30 21:04:55+0200 + + 2025-08-30 21:04:55 +0200 + + 2025-08-30 21:04:55+02:00 + + 2025-08-30 21:04:55 +02:00 + + 2025-08-30 21:04:55.123456+0200 + + 2025-08-30 21:04:55.123456 +02:00 + +| RFC 3339, date + heure UTC +| 2025-08-30 19:04:55Z + + 2025-08-30 19:04:55.123456Z + +| Heure locale +| 21:04:55 + + 21:04:55.123456 + +| Heure locale + décalage horaire +| 16:04:55-03 + + 16:04:55-0300 + + 21:04:55+0200 + + 21:04:55 +0200 + + 21:04:55+02:00 + + 21:04:55 +02:00 + + 21:04:55.123456+0200 + + 21:04:55.123456 +02:00 + +| Heure UTC +| 19:04:55Z + + 19:04:55.123456Z + +| Date d'horodatage +| 1756580695 + + 1756580695.123456 + + 1756580695,123456 +|=== + +Notes : + +* Pour ISO 8601, le séparateur entre la date et l'heure est `T` (majuscule) ou + `t` (minuscule). +* Pour l'heure UTC, le caractère final est `Z` (majuscule) ou `z` (minuscule). +* Le format du décalage horaire est l'un des suivants : +** `++[+/-]hh:mm++` (heures et minutes) +** `++[+/-]hhmm++` (heures et minutes) +** `++[+/-]hh++` (heures). +* La précision après les secondes peut aller d'un dixième de seconde (1 chiffre, + par exemple `21:04:55.1`) à une microseconde (6 chiffres, par exemple `21:04:55.123456`). + + Un point (`.`) ou une virgule (`,`) peut séparer les secondes des autres chiffres. + Valeur de retour : * 1 si OK, 0 si erreur -Exemple en C : +Exemples en C : [source,c] ---- struct timeval tv; -weechat_util_parse_time ("2023-12-25T10:29:09.456789Z", &tv); /* == 1 */ -/* result: tv.tv_sec == 1703500149, tv.tv_usec = 456789 */ + +weechat_util_parse_time ("2025-08-30T19:04:55.123456Z", &tv); /* == 1 */ +/* résultat : tv.tv_sec == 1756580695, tv.tv_usec = 123456 */ + +weechat_util_parse_time ("2025-08-30 21:04:55.123456 +02:00", &tv); /* == 1 */ +/* même résultat */ + +weechat_util_parse_time ("21:04:55.123456", &tv); /* == 1 */ +/* même résultat */ ---- [NOTE] diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 282f7a4f0..3205f546f 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -5081,20 +5081,106 @@ int util_parse_time (const char *datetime, struct timeval *tv); Arguments: -* _date_: date/time +* _date_: date/time (see supported formats below) * _tv_: parsed date/time ("timeval" structure) +Supported date/time format (supposing the current time is `2025-08-30 21:04:55` +(Europe/Paris), so with timezone offset `+02:00`, UTC time being `19:04:55`): + +[width="70%",cols="5,6m",options="header"] +|=== +| Format | Examples + +| Date (midnight) +| 2025-08-30 + +| ISO 8601, date + local time +| 2025-08-30T21:04:55 + + 2025-08-30T21:04:55.123456 + +| ISO 8601, date + local time + offset +| 2025-08-30T16:04:55-03 + + 2025-08-30T16:04:55-0300 + + 2025-08-30T21:04:55+0200 + + 2025-08-30T21:04:55+02:00 + + 2025-08-30T21:04:55.123456+0200 + +| ISO 8601, date + UTC time +| 2025-08-30T19:04:55Z + + 2025-08-30T19:04:55.123456Z + +| RFC 3339, date + local time +| 2025-08-30 21:04:55 + + 2025-08-30 21:04:55.123456 + +| RFC 3339, date + local time + offset +| 2025-08-30 16:04:55-03 + + 2025-08-30 16:04:55-0300 + + 2025-08-30 21:04:55+0200 + + 2025-08-30 21:04:55 +0200 + + 2025-08-30 21:04:55+02:00 + + 2025-08-30 21:04:55 +02:00 + + 2025-08-30 21:04:55.123456+0200 + + 2025-08-30 21:04:55.123456 +02:00 + +| RFC 3339, date + UTC time +| 2025-08-30 19:04:55Z + + 2025-08-30 19:04:55.123456Z + +| Local time +| 21:04:55 + + 21:04:55.123456 + +| Local time + offset +| 16:04:55-03 + + 16:04:55-0300 + + 21:04:55+0200 + + 21:04:55 +0200 + + 21:04:55+02:00 + + 21:04:55 +02:00 + + 21:04:55.123456+0200 + + 21:04:55.123456 +02:00 + +| UTC time +| 19:04:55Z + + 19:04:55.123456Z + +| Timestamp date +| 1756580695 + + 1756580695.123456 + + 1756580695,123456 +|=== + +Notes: + +* For ISO 8601, the separator between date and time is `T` (upper case) or `t` (lower case). +* For UTC time, the final char is `Z` (upper case) or `z` (lower case). +* The timezone offset format is one of: +** `++[+/-]hh:mm++` (hours and minutes) +** `++[+/-]hhmm++` (hours and minutes) +** `++[+/-]hh++` (hours). +* Precision after seconds can be from one-tenth of second (1 digit, for example + `21:04:55.1`) to one microsecond (6 digits, for example `21:04:55.123456`). + + A dot (`.`) or comma (`,`) can separate seconds from the other digits. + Return value: * 1 if OK, 0 if error -C example: +C examples: [source,c] ---- struct timeval tv; -weechat_util_parse_time ("2023-12-25T10:29:09.456789Z", &tv); /* == 1 */ -/* result: tv.tv_sec == 1703500149, tv.tv_usec = 456789 */ + +weechat_util_parse_time ("2025-08-30T19:04:55.123456Z", &tv); /* == 1 */ +/* result: tv.tv_sec == 1756580695, tv.tv_usec = 123456 */ + +weechat_util_parse_time ("2025-08-30 21:04:55.123456 +02:00", &tv); /* == 1 */ +/* same result */ + +weechat_util_parse_time ("21:04:55.123456", &tv); /* == 1 */ +/* same result */ ---- [NOTE] diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 63606fb7d..f1129e795 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -4995,20 +4995,106 @@ int util_parse_time (const char *datetime, struct timeval *tv); Arguments: -* _date_: date/time +* _date_: date/time (see supported formats below) * _tv_: parsed date/time ("timeval" structure) +Supported date/time format (supposing the current time is `2025-08-30 21:04:55` +(Europe/Paris), so with timezone offset `+02:00`, UTC time being `19:04:55`): + +[width="70%",cols="5,6m",options="header"] +|=== +| Format | Examples + +| Date (midnight) +| 2025-08-30 + +| ISO 8601, date + local time +| 2025-08-30T21:04:55 + + 2025-08-30T21:04:55.123456 + +| ISO 8601, date + local time + offset +| 2025-08-30T16:04:55-03 + + 2025-08-30T16:04:55-0300 + + 2025-08-30T21:04:55+0200 + + 2025-08-30T21:04:55+02:00 + + 2025-08-30T21:04:55.123456+0200 + +| ISO 8601, date + UTC time +| 2025-08-30T19:04:55Z + + 2025-08-30T19:04:55.123456Z + +| RFC 3339, date + local time +| 2025-08-30 21:04:55 + + 2025-08-30 21:04:55.123456 + +| RFC 3339, date + local time + offset +| 2025-08-30 16:04:55-03 + + 2025-08-30 16:04:55-0300 + + 2025-08-30 21:04:55+0200 + + 2025-08-30 21:04:55 +0200 + + 2025-08-30 21:04:55+02:00 + + 2025-08-30 21:04:55 +02:00 + + 2025-08-30 21:04:55.123456+0200 + + 2025-08-30 21:04:55.123456 +02:00 + +| RFC 3339, date + UTC time +| 2025-08-30 19:04:55Z + + 2025-08-30 19:04:55.123456Z + +| Local time +| 21:04:55 + + 21:04:55.123456 + +| Local time + offset +| 16:04:55-03 + + 16:04:55-0300 + + 21:04:55+0200 + + 21:04:55 +0200 + + 21:04:55+02:00 + + 21:04:55 +02:00 + + 21:04:55.123456+0200 + + 21:04:55.123456 +02:00 + +| UTC time +| 19:04:55Z + + 19:04:55.123456Z + +| Timestamp date +| 1756580695 + + 1756580695.123456 + + 1756580695,123456 +|=== + +Notes: + +* For ISO 8601, the separator between date and time is `T` (upper case) or `t` (lower case). +* For UTC time, the final char is `Z` (upper case) or `z` (lower case). +* The timezone offset format is one of: +** `++[+/-]hh:mm++` (hours and minutes) +** `++[+/-]hhmm++` (hours and minutes) +** `++[+/-]hh++` (hours). +* Precision after seconds can be from one-tenth of second (1 digit, for example + `21:04:55.1`) to one microsecond (6 digits, for example `21:04:55.123456`). + + A dot (`.`) or comma (`,`) can separate seconds from the other digits. + Return value: * 1 if OK, 0 if error -C example: +C examples: [source,c] ---- struct timeval tv; -weechat_util_parse_time ("2023-12-25T10:29:09.456789Z", &tv); /* == 1 */ -/* result: tv.tv_sec == 1703500149, tv.tv_usec = 456789 */ + +weechat_util_parse_time ("2025-08-30T19:04:55.123456Z", &tv); /* == 1 */ +/* result: tv.tv_sec == 1756580695, tv.tv_usec = 123456 */ + +weechat_util_parse_time ("2025-08-30 21:04:55.123456 +02:00", &tv); /* == 1 */ +/* same result */ + +weechat_util_parse_time ("21:04:55.123456", &tv); /* == 1 */ +/* same result */ ---- [NOTE] diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index 073533495..4b7733927 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -4719,20 +4719,111 @@ int util_parse_time (const char *datetime, struct timeval *tv); Аргументи: -* _date_: датум/време +// TRANSLATION MISSING +* _date_: датум/време (see supported formats below) * _tv_: парсиран датум/време („timeval” структура) +// TRANSLATION MISSING +Supported date/time format (supposing the current time is `2025-08-30 21:04:55` +(Europe/Paris), so with timezone offset `+02:00`, UTC time being `19:04:55`): + +// TRANSLATION MISSING +[width="70%",cols="5,6m",options="header"] +|=== +| Format | Examples + +| Date (midnight) +| 2025-08-30 + +| ISO 8601, date + local time +| 2025-08-30T21:04:55 + + 2025-08-30T21:04:55.123456 + +| ISO 8601, date + local time + offset +| 2025-08-30T16:04:55-03 + + 2025-08-30T16:04:55-0300 + + 2025-08-30T21:04:55+0200 + + 2025-08-30T21:04:55+02:00 + + 2025-08-30T21:04:55.123456+0200 + +| ISO 8601, date + UTC time +| 2025-08-30T19:04:55Z + + 2025-08-30T19:04:55.123456Z + +| RFC 3339, date + local time +| 2025-08-30 21:04:55 + + 2025-08-30 21:04:55.123456 + +| RFC 3339, date + local time + offset +| 2025-08-30 16:04:55-03 + + 2025-08-30 16:04:55-0300 + + 2025-08-30 21:04:55+0200 + + 2025-08-30 21:04:55 +0200 + + 2025-08-30 21:04:55+02:00 + + 2025-08-30 21:04:55 +02:00 + + 2025-08-30 21:04:55.123456+0200 + + 2025-08-30 21:04:55.123456 +02:00 + +| RFC 3339, date + UTC time +| 2025-08-30 19:04:55Z + + 2025-08-30 19:04:55.123456Z + +| Local time +| 21:04:55 + + 21:04:55.123456 + +| Local time + offset +| 16:04:55-03 + + 16:04:55-0300 + + 21:04:55+0200 + + 21:04:55 +0200 + + 21:04:55+02:00 + + 21:04:55 +02:00 + + 21:04:55.123456+0200 + + 21:04:55.123456 +02:00 + +| UTC time +| 19:04:55Z + + 19:04:55.123456Z + +| Timestamp date +| 1756580695 + + 1756580695.123456 + + 1756580695,123456 +|=== + +// TRANSLATION MISSING +Notes: + +* For ISO 8601, the separator between date and time is `T` (upper case) or `t` (lower case). +* For UTC time, the final char is `Z` (upper case) or `z` (lower case). +* The timezone offset format is one of: +** `++[+/-]hh:mm++` (hours and minutes) +** `++[+/-]hhmm++` (hours and minutes) +** `++[+/-]hh++` (hours). +* Precision after seconds can be from one-tenth of second (1 digit, for example + `21:04:55.1`) to one microsecond (6 digits, for example `21:04:55.123456`). + + A dot (`.`) or comma (`,`) can separate seconds from the other digits. + Повратна вредност: * 1 ако је OK, 0 у случају грешке -C пример: +C примери: +// TRANSLATION MISSING [source,c] ---- struct timeval tv; -weechat_util_parse_time ("2023-12-25T10:29:09.456789Z", &tv); /* == 1 */ -/* резултат: tv.tv_sec == 1703500149, tv.tv_usec = 456789 */ + +weechat_util_parse_time ("2025-08-30T19:04:55.123456Z", &tv); /* == 1 */ +/* резултат: tv.tv_sec == 1756580695, tv.tv_usec = 123456 */ + +weechat_util_parse_time ("2025-08-30 21:04:55.123456 +02:00", &tv); /* == 1 */ +/* same result */ + +weechat_util_parse_time ("21:04:55.123456", &tv); /* == 1 */ +/* same result */ ---- [NOTE] diff --git a/src/core/core-util.c b/src/core/core-util.c index 129930b73..f2e21b4e2 100644 --- a/src/core/core-util.c +++ b/src/core/core-util.c @@ -272,76 +272,28 @@ util_strftimeval (char *string, int max, const char *format, struct timeval *tv) /* * Parses a date/time string, which can be one of these formats: * - * "2024-01-04" -> date at midnight + * Format | Example + * -------------------------------------+---------------------------------- + * Date (midnight) | 2025-08-30 + * ISO 8601, date + local time | 2025-08-30T21:04:55.123456 + * ISO 8601, date + local time + offset | 2025-08-30T21:04:55.123456+0200 + * ISO 8601, date + UTC time | 2025-08-30T19:04:55.123456Z + * RFC 3339, date + local time | 2025-08-30 21:04:55.123456 + * RFC 3339, date + local time + offset | 2025-08-30 21:04:55.123456 +02:00 + * RFC 3339, date + UTC time | 2025-08-30 19:04:55.123456Z + * Local time | 21:04:55.123456 + * Local time + offset | 21:04:55.123456+0200 + * UTC time | 19:04:55.123456Z + * Timestamp date | 1756580695.123456 * - * "2024-01-04T22:01:02" -> ISO 8601, local time - * "2024-01-04T22:01:02.123" -> ISO 8601, local time, milliseconds - * "2024-01-04T22:01:02.123456" -> ISO 8601, local time, microseconds + * Notes : * - * "2024-01-04T22:01:02+0100" -> ISO 8601, local time + offset - * "2024-01-04T22:01:02+01:00" -> ISO 8601, local time + offset - * "2024-01-04T22:01:02.123+0100" -> ISO 8601, local time + offset, milliseconds - * "2024-01-04T22:01:02.123+01:00" -> ISO 8601, local time + offset, milliseconds - * "2024-01-04T22:01:02.123456+0100" -> ISO 8601, local time + offset, microseconds - * "2024-01-04T22:01:02.123456+01:00" -> ISO 8601, local time + offset, microseconds - * - * "2024-01-04T21:01:02Z" -> ISO 8601, UTC - * "2024-01-04T21:01:02.123Z" -> ISO 8601, UTC, milliseconds - * "2024-01-04T21:01:02.123456Z" -> ISO 8601, UTC, microseconds - * - * "2024-01-04 22:01:02" -> ~ISO 8601 (space), local time - * "2024-01-04 22:01:02.123" -> ~ISO 8601 (space), local time, milliseconds - * "2024-01-04 22:01:02.123456" -> ~ISO 8601 (space), local time, microseconds - * - * "2024-01-04 22:01:02+0100" -> ~ISO 8601 (space), local time + offset - * "2024-01-04 22:01:02+01:00" -> ~ISO 8601 (space), local time + offset - * "2024-01-04 22:01:02 +0100" -> ~ISO 8601 (space), local time + offset - * "2024-01-04 22:01:02 +01:00" -> ~ISO 8601 (space), local time + offset - * "2024-01-04 22:01:02.123" -> ~ISO 8601 (space), local time + offset, milliseconds - * "2024-01-04 22:01:02.123+0100" -> ~ISO 8601 (space), local time + offset, milliseconds - * "2024-01-04 22:01:02.123+01:00" -> ~ISO 8601 (space), local time + offset, milliseconds - * "2024-01-04 22:01:02.123 +0100" -> ~ISO 8601 (space), local time + offset, milliseconds - * "2024-01-04 22:01:02.123 +01:00" -> ~ISO 8601 (space), local time + offset, milliseconds - * "2024-01-04 22:01:02.123456" -> ~ISO 8601 (space), local time + offset, microseconds - * "2024-01-04 22:01:02.123456+0100" -> ~ISO 8601 (space), local time + offset, microseconds - * "2024-01-04 22:01:02.123456+01:00" -> ~ISO 8601 (space), local time + offset, microseconds - * "2024-01-04 22:01:02.123456 +0100" -> ~ISO 8601 (space), local time + offset, microseconds - * "2024-01-04 22:01:02.123456 +01:00" -> ~ISO 8601 (space), local time + offset, microseconds - * - * "2024-01-04 21:01:02Z" -> ~ISO 8601 (space), UTC - * "2024-01-04 21:01:02.123Z" -> ~ISO 8601 (space), UTC, milliseconds - * "2024-01-04 21:01:02.123456Z" -> ~ISO 8601 (space), UTC, microseconds - * - * "22:01:02" -> current date, local time - * "22:01:02.123" -> current date, local time, milliseconds - * "22:01:02.123456" -> current date, local time, microseconds - * - * "22:01:02+0100" -> current date, local time + offset - * "22:01:02+01:00" -> current date, local time + offset - * "22:01:02 +0100" -> current date, local time + offset - * "22:01:02 +01:00" -> current date, local time + offset - * "22:01:02.123" -> current date, local time + offset, milliseconds - * "22:01:02.123+0100" -> current date, local time + offset, milliseconds - * "22:01:02.123+01:00" -> current date, local time + offset, milliseconds - * "22:01:02.123 +0100" -> current date, local time + offset, milliseconds - * "22:01:02.123 +01:00" -> current date, local time + offset, milliseconds - * "22:01:02.123456" -> current date, local time + offset, microseconds - * "22:01:02.123456+0100" -> current date, local time + offset, microseconds - * "22:01:02.123456+01:00" -> current date, local time + offset, microseconds - * "22:01:02.123456 +0100" -> current date, local time + offset, microseconds - * "22:01:02.123456 +01:00" -> current date, local time + offset, microseconds - * - * "21:01:02Z" -> current date, UTC - * "21:01:02.123Z" -> current date, UTC, milliseconds - * "21:01:02.123456Z" -> current date, UTC, microseconds - * - * "1704402062" -> timestamp date - * "1704402062.123" -> timestamp date, milliseconds - * "1704402062,123" -> timestamp date, milliseconds - * "1704402062.123456" -> timestamp date, microseconds - * "1704402062,123456" -> timestamp date, microseconds - * - * Note: lower characters "t" and "z" are also supported. + * - For ISO 8601, characters `T' and `Z` can be used in lower case: `t` and `z`. + * - The timezone offset format is `[+/-]hh:mm`, `[+/-]hhmm` or `[+/-]hh`. + * - Precision after seconds can be from one-tenth of second (1 digit, like + * `21:04:55.1`) to one microsecond (6 digits, like `21:04:55.123456`). + * A dot (`.`) or comma (`,`) can be used to separate seconds from the other + * digits. * * Returns: * 1: OK @@ -375,7 +327,7 @@ util_parse_time (const char *datetime, struct timeval *tv) pos_dot = strchr (datetime, '.'); if (pos_colon && !pos_hyphen) { - /* add current date: "21:01:02" -> "2024-01-04T21:01:02" */ + /* add current date: "19:04:55" -> "2025-08-30T19:04:55" */ string = malloc (strlen (datetime) + 16 + 1); if (!string) return 0; @@ -386,7 +338,7 @@ util_parse_time (const char *datetime, struct timeval *tv) } else if (!pos_colon && pos_hyphen && (!pos_dot || (pos_hyphen < pos_dot))) { - /* add time (midnight): "2024-01-04" -> "2024-01-04T00:00:00" */ + /* add time (midnight): "2025-08-30" -> "2025-08-30T00:00:00" */ string = malloc (strlen (datetime) + 16 + 1); if (!string) return 0; @@ -502,7 +454,7 @@ util_parse_time (const char *datetime, struct timeval *tv) { if (strchr (string, 'T')) { - /* ISO 8601 format like: "2024-01-04T21:01:02" */ + /* ISO 8601 format like: "2025-08-30T19:04:55" */ /* initialize structure, because strptime does not do it */ memset (&tm_date, 0, sizeof (struct tm)); pos = strptime (string, "%Y-%m-%dT%H:%M:%S", &tm_date); @@ -530,7 +482,7 @@ util_parse_time (const char *datetime, struct timeval *tv) } else if (strchr (string, 't')) { - /* ISO 8601 format like: "2024-01-04t21:01:02" */ + /* ISO 8601 format like: "2025-08-30t19:04:55" */ /* initialize structure, because strptime does not do it */ memset (&tm_date, 0, sizeof (struct tm)); pos = strptime (string, "%Y-%m-%dt%H:%M:%S", &tm_date); @@ -558,7 +510,7 @@ util_parse_time (const char *datetime, struct timeval *tv) } else { - /* like ISO 8601 but with space like: "2024-01-04 21:01:02" */ + /* like ISO 8601 but with space like: "2025-08-30 19:04:55" */ /* initialize structure, because strptime does not do it */ memset (&tm_date, 0, sizeof (struct tm)); pos = strptime (string, "%Y-%m-%d %H:%M:%S", &tm_date);