1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 23:36:37 +02:00

core: use function util_strftimeval in evaluation of expression date:xxx

This commit is contained in:
Sébastien Helleu
2024-01-27 12:15:40 +01:00
parent e3af6a91d4
commit 2469dc6df9
8 changed files with 52 additions and 28 deletions
+1
View File
@@ -16,6 +16,7 @@ For a list of important changes that require manual actions, please look at rele
New features::
* core: allow case insensitive search of partial buffer name with `(?i)name` in command `/buffer`
* core: use function util_strftimeval in evaluation of expression `date:xxx`
* api: add support of specifier `%!` for timestamp in function util_strftimeval
Bug fixes::
+6 -3
View File
@@ -2567,7 +2567,7 @@ str3 = weechat.string_input_for_buffer("//test") # "/test"
==== string_eval_expression
_WeeChat ≥ 0.4.0, updated in 0.4.2, 0.4.3, 1.0, 1.1, 1.2, 1.3, 1.6, 1.8, 2.0,
2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6, 3.8, 4.0.0, 4.2.0._
2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6, 3.8, 4.0.0, 4.2.0, 4.3.0._
Evaluate an expression and return result as a string.
Special variables with format `+${variable}+` are expanded (see table below).
@@ -3208,13 +3208,16 @@ expanded to last):
| `+${date}+` +
`+${date:xxx}+` | 1.3
| Current date/time, with custom format (see `man strftime`),
| Current date/time, with custom format (see function <<_util_strftimeval,util_strftimeval>>),
default format is `%F %T`.
| >> `+${date}+` +
== `+2015-06-30 19:02:45+` +
+
>> `+${date:%H:%M:%S}+` +
== `+19:02:45+`
== `+19:02:45+` +
+
>> `+${date:%!.%.3}+` +
== `+1435683765.482+`
| `+${env:NAME}+` | 1.2
| Value of the environment variable `NAME`.
+7 -4
View File
@@ -2613,7 +2613,7 @@ str3 = weechat.string_input_for_buffer("//test") # "/test"
==== string_eval_expression
_WeeChat ≥ 0.4.0, mis à jour dans la 0.4.2, 0.4.3, 1.0, 1.1, 1.2, 1.3, 1.6, 1.8,
2.0, 2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6, 3.8, 4.0.0, 4.2.0._
2.0, 2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6, 3.8, 4.0.0, 4.2.0, 4.3.0._
Évaluer l'expression et retourner le résultat sous forme de chaîne.
Les variables spéciales avec le format `+${variable}+` sont étendues (voir le
@@ -3263,13 +3263,16 @@ première étendue à la dernière) :
| `+${date}+` +
`+${date:xxx}+` | 1.3
| La date/heure courante, avec un format personnalisé (voir `man strftime`),
le format par défaut est `%F %T`.
| La date/heure courante, avec un format personnalisé (voir la fonction
<<_util_strftimeval,util_strftimeval>>), le format par défaut est `%F %T`.
| >> `+${date}+` +
== `+2015-06-30 19:02:45+` +
+
>> `+${date:%H:%M:%S}+` +
== `+19:02:45+`
== `+19:02:45+` +
+
>> `+${date:%!.%.3}+` +
== `+1435683765.482+`
| `+${env:NOM}+` | 1.2
| Valeur de la variable d'environnement `NOM`.
+6 -3
View File
@@ -2717,7 +2717,7 @@ str3 = weechat.string_input_for_buffer("//test") # "/test"
==== string_eval_expression
_WeeChat ≥ 0.4.0, updated in 0.4.2, 0.4.3, 1.0, 1.1, 1.2, 1.3, 1.6, 1.8, 2.0,
2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6, 3.8, 4.0.0, 4.2.0._
2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6, 3.8, 4.0.0, 4.2.0, 4.3.0._
Evaluate an expression and return result as a string.
Special variables with format `+${variable}+` are expanded (see table below).
@@ -3357,13 +3357,16 @@ expanded to last):
| `+${date}+` +
`+${date:xxx}+` | 1.3
| Current date/time, with custom format (see `man strftime`),
| Current date/time, with custom format (see function <<_util_strftimeval,util_strftimeval>>),
default format is `%F %T`.
| >> `+${date}+` +
== `+2015-06-30 19:02:45+` +
+
>> `+${date:%H:%M:%S}+` +
== `+19:02:45+`
== `+19:02:45+` +
+
>> `+${date:%!.%.3}+` +
== `+1435683765.482+`
| `+${env:NAME}+` | 1.2
| Value of the environment variable `NAME`.
+7 -3
View File
@@ -2637,7 +2637,7 @@ str3 = weechat.string_input_for_buffer("//test") # "/test"
// TRANSLATION MISSING
_WeeChat ≥ 0.4.0, updated in 0.4.2, 0.4.3, 1.0, 1.1, 1.2, 1.3, 1.6, 1.8, 2.0,
2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6, 3.8, 4.0.0, 4.2.0._
2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6, 3.8, 4.0.0, 4.2.0, 4.3.0._
式を評価して文字列として返す。`+${variable}+`
という書式で書かれた特殊変数は展開されます (以下の表を参照)。
@@ -3304,15 +3304,19 @@ str5 = weechat.string_eval_expression("password=abc password=def", {}, {}, optio
>> `+${base_decode:64,dGVzdCBzdHJpbmc=}+` +
== `+test string+`
// TRANSLATION MISSING
| `+${date}+` +
`+${date:xxx}+` | 1.3
| 現在の日付/時刻、カスタム書式を使うことも可能です (`man strftime` を参照)、
| 現在の日付/時刻、カスタム書式を使うことも可能です (see function <<_util_strftimeval,util_strftimeval>>)、
デフォルト書式は `%F %T`
| >> `+${date}+` +
== `+2015-06-30 19:02:45+` +
+
>> `+${date:%H:%M:%S}+` +
== `+19:02:45+`
== `+19:02:45+` +
+
>> `+${date:%!.%.3}+` +
== `+1435683765.482+`
| `+${env:NAME}+` | 1.2
| 環境変数 `NAME` の値
+7 -3
View File
@@ -2479,7 +2479,7 @@ str3 = weechat.string_input_for_buffer("//test") # "/test"
==== string_eval_expression
_WeeChat ≥ 0.4.0, ажурирано у верзијама 0.4.2, 0.4.3, 1.0, 1.1, 1.2, 1.3, 1.6, 1.8, 2.0, 2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6 и 3.8, 4.0.0, 4.2.0._
_WeeChat ≥ 0.4.0, ажурирано у верзијама 0.4.2, 0.4.3, 1.0, 1.1, 1.2, 1.3, 1.6, 1.8, 2.0, 2.2, 2.3, 2.7, 2.9, 3.1, 3.2, 3.3, 3.4, 3.6 и 3.8, 4.0.0, 4.2.0, 4.3.0._
Израчунава израз и враћа вредност као стринг. Специјалне променљиве у формату `+${променљива}+` се развијају (погледајте табелу испод).
@@ -3094,15 +3094,19 @@ str5 = weechat.string_eval_expression("password=abc password=def", {}, {}, optio
>> `+${base_decode:64,dGVzdCBzdHJpbmc=}+` +
== `+test string+`
// TRANSLATION MISSING
| `+${date}+` +
`+${date:xxx}+` | 1.3
| Текући датум/време, у прилагођеном формату (погледајте `man strftime`),
| Текући датум/време, у прилагођеном формату (see function <<_util_strftimeval,util_strftimeval>>),
подразумевани формат је `%F %T`.
| >> `+${date}+` +
== `+2015-06-30 19:02:45+` +
+
>> `+${date:%H:%M:%S}+` +
== `+19:02:45+`
== `+19:02:45+` +
+
>> `+${date:%!.%.3}+` +
== `+1435683765.482+`
| `+${env:ИМЕ}+` | 1.2
| Име променљиве окружења `ИМЕ`.
+7 -11
View File
@@ -28,6 +28,7 @@
#include <stdarg.h>
#include <regex.h>
#include <time.h>
#include <sys/time.h>
#include "weechat.h"
#include "wee-eval.h"
@@ -39,6 +40,7 @@
#include "wee-secure.h"
#include "wee-string.h"
#include "wee-utf8.h"
#include "wee-util.h"
#include "../gui/gui-buffer.h"
#include "../gui/gui-chat.h"
#include "../gui/gui-color.h"
@@ -988,19 +990,13 @@ char *
eval_string_date (const char *text)
{
char str_value[512];
time_t date;
struct tm *date_tmp;
struct timeval tv_now;
int rc;
date = time (NULL);
date_tmp = localtime (&date);
if (!date_tmp)
return strdup ("");
rc = (int) strftime (str_value, sizeof (str_value),
(text[0] == ':') ? text + 1 : "%F %T",
date_tmp);
gettimeofday (&tv_now, NULL);
rc = util_strftimeval (str_value, sizeof (str_value),
(text[0] == ':') ? text + 1 : "%F %T",
&tv_now);
return strdup ((rc > 0) ? str_value : "");
}
+11 -1
View File
@@ -26,6 +26,7 @@ extern "C"
#include <stdio.h>
#include <string.h>
#include <regex.h>
#include <time.h>
#include "src/core/wee-eval.h"
#include "src/core/wee-config.h"
#include "src/core/wee-config-file.h"
@@ -453,8 +454,10 @@ TEST(CoreEval, EvalExpression)
{
struct t_hashtable *pointers, *extra_vars, *options;
struct t_config_option *ptr_option;
char *value, str_value[256], str_expr[256];
char *value, str_value[256], str_expr[256], *error;
const char *ptr_debug_output;
long number;
time_t time_now;
pointers = hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
@@ -898,6 +901,13 @@ TEST(CoreEval, EvalExpression)
pointers, extra_vars, options);
LONGS_EQUAL(8, strlen (value));
free (value);
value = eval_expression ("${date:%!}", pointers, extra_vars, options);
CHECK(value);
error = NULL;
number = strtol (value, &error, 10);
CHECK(error && !error[0]);
time_now = time (NULL);
CHECK((number >= time_now - 10) && (number <= time_now + 10));
/* test ternary operator */
WEE_CHECK_EVAL("1", "${if:5>2}");