[PATCH 4/4] test: give unique timestamps to messages
Tomi Ollila
tomi.ollila at iki.fi
Mon Dec 9 00:20:51 PST 2013
On Mon, Dec 09 2013, David Bremner <david at tethera.net> wrote:
> Tomi Ollila <tomi.ollila at iki.fi> writes:
>
>>> if [ -z "${template[date]}" ]; then
>>> - template[date]="Fri, 05 Jan 2001 15:43:57 +0000"
>>> + template[date]=$(date -Ru -d@$((978709437 - gen_msg_cnt)))
>>
>> I am afraid this is not portable (although not sure). This could work:
>>
>> _s=$((3599 - gen_msg_cnt))
>> template[date]="Fri, 05 Jan 2001 15:$((_s / 60)):$((_s % 60)) +0000"
>>
>
> How about this instead?
>
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 792e477..22a4d7f 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -356,7 +356,8 @@ generate_message ()
> fi
>
> if [ -z "${template[date]}" ]; then
> - template[date]=$(date -Ru -d@$((978709437 - gen_msg_cnt)))
> + template[date]=$(TZ=UTC printf "%(%a, %d %b %Y %T %z)T\n" \
> + $((978709437 - gen_msg_cnt)))
> fi
$ printf "%(%a, %d %b %Y %T %z)T\n" 978709437
printf: %(: invalid directive
zsh: exit 1
$ bash -c 'printf "%(%a, %d %b %Y %T %z)T\n" 978709437'
Fri, 05 Jan 2001 17:43:57 +0200
Using bash builtin is fine by me! :D
BTW: this works too:
bash -c 'TZ=UTC printf -v foo[bar] "%(%a, %d %b %Y %T %z)T\n" 978709437; echo ${foo[bar]}'
Tomi
More information about the notmuch
mailing list