47494, 47495: Add -n option to strftime

This commit is contained in:
Mikael Magnusson 2020-10-24 13:45:08 +02:00
parent ea64d2fd4b
commit 8773f01f2b
5 changed files with 23 additions and 9 deletions

View file

@ -6,6 +6,10 @@
* 47302: Test/B03print.ztst, Test/D07multibyte.ztst: Test for
print -v fix
* 47494, 47495: Completion/Zsh/Command/_strftime,
Doc/Zsh/mod_datetime.yo, Src/Modules/datetime.c,
Test/V09datetime.ztst: Add -n option to strftime
2020-10-18 Roman Perepelitsa <roman.perepelitsa@gmail.com>
* 47476: Src/Modules/files.c: Fix a race condition in zf_mkdir -p

View file

@ -1,14 +1,16 @@
#compdef strftime
local ret=1 expl
local expl two='epoch time'
if (( words[(I)-r] )); then
two='date string'
fi
_arguments -S -A '-*' -s \
'-n[omit trailing newline]' \
'-q[run quietly]' \
'(3)-r[reverse lookup using strptime]' \
'-s+[assign result to parameter]:param:_parameters' \
'1:format: _date_formats zsh' \
'2:epoch time (or date string with -r)' \
"2:$two" \
'3:nanoseconds' \
&& ret=0
return ret

View file

@ -6,8 +6,8 @@ The tt(zsh/datetime) module makes available one builtin command:
startitem()
findex(strftime)
cindex(date string, printing)
xitem(tt(strftime) [ tt(-s) var(scalar) ] var(format) [ var(epochtime) [ var(nanoseconds) ] ] )
item(tt(strftime) tt(-r) [ tt(-q) ] [ tt(-s) var(scalar) ] var(format) var(timestring) )(
xitem(tt(strftime) [ tt(-s) var(scalar) | tt(-n) ] var(format) [ var(epochtime) [ var(nanoseconds) ] ] )
item(tt(strftime) tt(-r) [ tt(-q) ] [ tt(-s) var(scalar) | tt(-n) ] var(format) var(timestring) )(
Output the date in the var(format) specified. With no var(epochtime), the
current system date/time is used; optionally, var(epochtime) may be used to
specify the number of seconds since the epoch, and var(nanoseconds) may
@ -18,6 +18,9 @@ ifzman(the section EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc))\
ifnzman(noderef(Prompt Expansion)) are also available.
startitem()
item(tt(-n))(
Suppress printing a newline after the formatted string.
)
item(tt(-q))(
Run quietly; suppress printing of all error messages described below.
Errors for invalid var(epochtime) values are always printed.

View file

@ -175,7 +175,8 @@ output_strftime(char *nam, char **argv, Options ops, UNUSED(int func))
setsparam(scalar, metafy(buffer, len, META_DUP));
} else {
fwrite(buffer, 1, len, stdout);
putchar('\n');
if (!OPT_ISSET(ops,'n'))
putchar('\n');
}
zfree(buffer, bufsize);
@ -235,7 +236,7 @@ getcurrenttime(UNUSED(Param pm))
}
static struct builtin bintab[] = {
BUILTIN("strftime", 0, bin_strftime, 1, 3, 0, "qrs:", NULL),
BUILTIN("strftime", 0, bin_strftime, 1, 3, 0, "nqrs:", NULL),
};
static const struct gsu_integer epochseconds_gsu =

View file

@ -130,3 +130,7 @@
>%6. 2002-02-02 02:02:02.999999
>%9. 2002-02-02 02:02:02.999999999
>%12. 2002-02-02 02:02:02.999999999
strftime -n 'one line%n' 2> /dev/null
0:-n option
>one line