diff --git a/osh/builtin_printf.py b/osh/builtin_printf.py index 4c796b4ee3..08be1ae4d8 100755 --- a/osh/builtin_printf.py +++ b/osh/builtin_printf.py @@ -115,7 +115,7 @@ def _ParseFormatStr(self): p_die(msg, token=self.cur_token) # Do this check AFTER the floating point checks - if part.precision and part.type.val not in 'fs': + if part.precision and part.type.val[-1] not in 'fsT': p_die("precision can't be specified when here", token=part.precision) @@ -329,6 +329,8 @@ def Run(self, cmd_val): elif d == -2: # shell start time d = shell_start_time s = time.strftime(typ[1:-2], time.localtime(d)); + if precision is not None: + s = s[:precision] # truncate else: raise AssertionError() diff --git a/spec/builtin-printf.test.sh b/spec/builtin-printf.test.sh index 8b14c140eb..98e93ef84e 100644 --- a/spec/builtin-printf.test.sh +++ b/spec/builtin-printf.test.sh @@ -584,3 +584,19 @@ status=0 ## N-I dash/mksh/zsh/ash STDOUT: status=1 ## END + +#### %10.5(strftime format)T +# The result depends on timezone +export TZ=Asia/Tokyo +printf '[%10.5(%Y-%m-%d)T]\n' 1557978599 +export TZ=US/Eastern +printf '[%10.5(%Y-%m-%d)T]\n' 1557978599 +echo status=$? +## STDOUT: +[ 2019-] +[ 2019-] +status=0 +## END +## N-I dash/mksh/zsh/ash STDOUT: +[[status=1 +## END