mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
core: add support of specifier %@ for UTC time in function util_strftimeval
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# WeeChat ChangeLog
|
||||
|
||||
## Version 4.6.4 (under dev)
|
||||
|
||||
### Added
|
||||
|
||||
- core: add support of specifier `%@` for UTC time in function util_strftimeval
|
||||
|
||||
## Version 4.6.3 (2025-05-11)
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -4762,7 +4762,7 @@ This function is not available in scripting API.
|
||||
|
||||
==== util_strftimeval
|
||||
|
||||
_WeeChat ≥ 4.2.0, updated in 4.3.0._
|
||||
_WeeChat ≥ 4.2.0, updated in 4.3.0, 4.6.4._
|
||||
|
||||
Format date and time like function `strftime` in C library, using `struct timeval`
|
||||
as input, and supporting extra specifiers.
|
||||
@@ -4779,6 +4779,8 @@ Arguments:
|
||||
* _string_: buffer where the formatted string is stored
|
||||
* _max_: string size
|
||||
* _format_: format, the same as _strftime_ function, with these extra specifiers:
|
||||
** `%@`: return the date expressed in Coordinated Universal Time (UTC)
|
||||
instead of date relative to the user's specified timezone _(WeeChat ≥ 4.7.0)_
|
||||
** `%.N` where `N` is between 1 and 6: zero-padded microseconds on N digits
|
||||
(for example `%.3` for milliseconds)
|
||||
** `%f`: alias of `%.6`
|
||||
@@ -4795,8 +4797,8 @@ C example:
|
||||
char time[256];
|
||||
struct timeval tv;
|
||||
gettimeofday (&tv, NULL);
|
||||
weechat_util_strftimeval (time, sizeof (time), "%FT%T.%f", &tv);
|
||||
/* result: 2023-12-26T18:10:04.460509 */
|
||||
weechat_util_strftimeval (time, sizeof (time), "%@%FT%T.%fZ", &tv);
|
||||
/* result: 2023-12-26T18:10:04.460509Z */
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
|
||||
@@ -4841,7 +4841,7 @@ Cette fonction n'est pas disponible dans l'API script.
|
||||
|
||||
==== util_strftimeval
|
||||
|
||||
_WeeChat ≥ 4.2.0, mis à jour dans la 4.3.0._
|
||||
_WeeChat ≥ 4.2.0, mis à jour dans la 4.3.0, 4.6.4._
|
||||
|
||||
Formatter la date et l'heure comme la fonction `strftime` de la bibliothèque C,
|
||||
en utilisant un `struct timeval` en entrée et en supportant des caractères de
|
||||
@@ -4860,6 +4860,8 @@ Paramètres :
|
||||
* _max_ : taille de la chaîne
|
||||
* _format_ : format, le même que celui de la fonction _strftime_, avec des
|
||||
caractères de conversion supplémentaires :
|
||||
** `%@` : retourner la date exprimée en Temps Universel Coordonné (UTC)
|
||||
au lieu de la date relative au fuseau horaire de l'utilisateur _(WeeChat ≥ 4.7.0)_
|
||||
** `%.N` où `N` est entre 1 and 6: microsecondes remplies avec des zéros sur
|
||||
N chiffres (par exemple `%.3` pour les millisecondes)
|
||||
** `%f` : alias de `%.6`
|
||||
@@ -4876,8 +4878,8 @@ Exemple en C :
|
||||
char time[256];
|
||||
struct timeval tv;
|
||||
gettimeofday (&tv, NULL);
|
||||
weechat_util_strftimeval (time, sizeof (time), "%FT%T.%f", &tv);
|
||||
/* résultat : 2023-12-26T18:10:04.460509 */
|
||||
weechat_util_strftimeval (time, sizeof (time), "%@%FT%T.%fZ", &tv);
|
||||
/* résultat : 2023-12-26T18:10:04.460509Z */
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
|
||||
@@ -4985,7 +4985,7 @@ Questa funzione non è disponibile nelle API per lo scripting.
|
||||
// TRANSLATION MISSING
|
||||
==== util_strftimeval
|
||||
|
||||
_WeeChat ≥ 4.2.0, updated in 4.3.0._
|
||||
_WeeChat ≥ 4.2.0, updated in 4.3.0, 4.6.4._
|
||||
|
||||
Format date and time like function `strftime` in C library, using `struct timeval`
|
||||
as input, and supporting extra specifiers.
|
||||
@@ -5002,6 +5002,8 @@ Arguments:
|
||||
* _string_: buffer where the formatted string is stored
|
||||
* _max_: string size
|
||||
* _format_: format, the same as _strftime_ function, with these extra specifiers:
|
||||
** `%@`: return the date expressed in Coordinated Universal Time (UTC)
|
||||
instead of date relative to the user's specified timezone _(WeeChat ≥ 4.7.0)_
|
||||
** `%.N` where `N` is between 1 and 6: zero-padded microseconds on N digits
|
||||
(for example `%.3` for milliseconds)
|
||||
** `%f`: alias of `%.6`
|
||||
@@ -5018,8 +5020,8 @@ C example:
|
||||
char time[256];
|
||||
struct timeval tv;
|
||||
gettimeofday (&tv, NULL);
|
||||
weechat_util_strftimeval (time, sizeof (time), "%FT%T.%f", &tv);
|
||||
/* result: 2023-12-26T18:10:04.460509 */
|
||||
weechat_util_strftimeval (time, sizeof (time), "%@%FT%T.%fZ", &tv);
|
||||
/* result: 2023-12-26T18:10:04.460509Z */
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
|
||||
@@ -4898,7 +4898,7 @@ weechat_printf (NULL, "date: %s",
|
||||
// TRANSLATION MISSING
|
||||
==== util_strftimeval
|
||||
|
||||
_WeeChat ≥ 4.2.0, updated in 4.3.0._
|
||||
_WeeChat ≥ 4.2.0, updated in 4.3.0, 4.6.4._
|
||||
|
||||
Format date and time like function `strftime` in C library, using `struct timeval`
|
||||
as input, and supporting extra specifiers.
|
||||
@@ -4915,6 +4915,8 @@ Arguments:
|
||||
* _string_: buffer where the formatted string is stored
|
||||
* _max_: string size
|
||||
* _format_: format, the same as _strftime_ function, with these extra specifiers:
|
||||
** `%@`: return the date expressed in Coordinated Universal Time (UTC)
|
||||
instead of date relative to the user's specified timezone _(WeeChat ≥ 4.7.0)_
|
||||
** `%.N` where `N` is between 1 and 6: zero-padded microseconds on N digits
|
||||
(for example `%.3` for milliseconds)
|
||||
** `%f`: alias of `%.6`
|
||||
@@ -4931,8 +4933,8 @@ C example:
|
||||
char time[256];
|
||||
struct timeval tv;
|
||||
gettimeofday (&tv, NULL);
|
||||
weechat_util_strftimeval (time, sizeof (time), "%FT%T.%f", &tv);
|
||||
/* result: 2023-12-26T18:10:04.460509 */
|
||||
weechat_util_strftimeval (time, sizeof (time), "%@%FT%T.%fZ", &tv);
|
||||
/* result: 2023-12-26T18:10:04.460509Z */
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
|
||||
@@ -4624,7 +4624,7 @@ weechat_printf (NULL, "date: %s",
|
||||
|
||||
==== util_strftimeval
|
||||
|
||||
_WeeChat ≥ 4.2.0, ажурирано у 4.3.0._
|
||||
_WeeChat ≥ 4.2.0, ажурирано у 4.3.0, 4.6.4._
|
||||
|
||||
Форматира датум и време као функција `strftime` из C библиотеке, користећи `struct timeval`
|
||||
као улаз уз подршку за додатне спецификаторе.
|
||||
@@ -4641,6 +4641,9 @@ int weechat_util_strftimeval (char *string, int max, const char *format, struct
|
||||
* _string_: бафер у који се смешта форматирани стринг
|
||||
* _max_: величина стринга
|
||||
* _format_: формат, исто као за _strftime_ функцију, са следећим додатним спецификаторима:
|
||||
// TRANSLATION MISSING
|
||||
** `%@`: return the date expressed in Coordinated Universal Time (UTC)
|
||||
instead of date relative to the user's specified timezone _(WeeChat ≥ 4.7.0)_
|
||||
** `%.N` где је `N` између 1 и 6: микросекунде допуњене нулама на N цифара
|
||||
(на пример `%.3` за милисекунде)
|
||||
** `%f`: алијас за `%.6`
|
||||
@@ -4657,8 +4660,8 @@ C пример:
|
||||
char time[256];
|
||||
struct timeval tv;
|
||||
gettimeofday (&tv, NULL);
|
||||
weechat_util_strftimeval (time, sizeof (time), "%FT%T.%f", &tv);
|
||||
/* резултат: 2023-12-26T18:10:04.460509 */
|
||||
weechat_util_strftimeval (time, sizeof (time), "%@%FT%T.%fZ", &tv);
|
||||
/* резултат: 2023-12-26T18:10:04.460509Z */
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
|
||||
+16
-5
@@ -166,6 +166,8 @@ util_get_time_string (const time_t *date)
|
||||
/*
|
||||
* Formats date and time like strftime (but with timeval structure as input)
|
||||
* and adds extra specifiers:
|
||||
* - "%@": return the date expressed in Coordinated Universal Time (UTC)
|
||||
* instead of date relative to the user's specified timezone
|
||||
* - "%.1" to "%.6": first N digits of microseconds, zero-padded
|
||||
* - "%f": alias of "%.6" (microseconds, zero-padded to 6 digits)
|
||||
* - "%!": timestamp as integer, in seconds (value of tv->tv_sec)
|
||||
@@ -176,14 +178,15 @@ util_strftimeval (char *string, int max, const char *format, struct timeval *tv)
|
||||
{
|
||||
char **format2, str_temp[32];
|
||||
const char *ptr_format;
|
||||
struct tm *local_time;
|
||||
int length, bytes;
|
||||
struct tm *date_time;
|
||||
int length, bytes, local_time;
|
||||
long usec;
|
||||
|
||||
if (!string || (max <= 0) || !format || !tv)
|
||||
return 0;
|
||||
|
||||
string[0] = '\0';
|
||||
local_time = 1;
|
||||
|
||||
if (!format[0])
|
||||
return 0;
|
||||
@@ -206,6 +209,11 @@ util_strftimeval (char *string, int max, const char *format, struct timeval *tv)
|
||||
string_dyn_concat (format2, "%%", -1);
|
||||
ptr_format += 2;
|
||||
}
|
||||
else if ((ptr_format[0] == '%') && (ptr_format[1] == '@'))
|
||||
{
|
||||
local_time = 0;
|
||||
ptr_format += 2;
|
||||
}
|
||||
else if ((ptr_format[0] == '%') && (ptr_format[1] == '.'))
|
||||
{
|
||||
if ((ptr_format[2] >= '1') && (ptr_format[2] <= '6'))
|
||||
@@ -242,14 +250,17 @@ util_strftimeval (char *string, int max, const char *format, struct timeval *tv)
|
||||
}
|
||||
}
|
||||
|
||||
local_time = localtime (&(tv->tv_sec));
|
||||
if (!local_time)
|
||||
if (local_time)
|
||||
date_time = localtime (&(tv->tv_sec));
|
||||
else
|
||||
date_time = gmtime (&(tv->tv_sec));
|
||||
if (!date_time)
|
||||
{
|
||||
string_dyn_free (format2, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bytes = strftime (string, max, *format2, local_time);
|
||||
bytes = strftime (string, max, *format2, date_time);
|
||||
|
||||
string_dyn_free (format2, 1);
|
||||
|
||||
|
||||
@@ -185,6 +185,11 @@ TEST(CoreUtil, Strftimeval)
|
||||
"%H:%M:%S", &tv));
|
||||
STRCMP_EQUAL("10:29:09", str_time);
|
||||
|
||||
strcpy (str_time, "test");
|
||||
LONGS_EQUAL(8, util_strftimeval (str_time, sizeof (str_time),
|
||||
"%@%H:%M:%S", &tv));
|
||||
STRCMP_EQUAL("10:29:09", str_time);
|
||||
|
||||
strcpy (str_time, "test");
|
||||
LONGS_EQUAL(19, util_strftimeval (str_time, sizeof (str_time),
|
||||
"%Y-%m-%d %H:%M:%S", &tv));
|
||||
|
||||
Reference in New Issue
Block a user