Compare commits

...
2 Commits
Author SHA1 Message Date
Iain cca3bdfbef fix(web-search)!: remove ask.com, which has shut down (#14244)
BREAKING CHANGE: the `ask` engine and alias are removed from the web-search plugin, because Ask.com has shut down.
2026-11-06 05:42:13 -08:00
Wei-Lun Li 59ff4d042e fix(timer): round duration before splitting off minutes (#14246) 2026-11-06 05:40:48 -08:00
4 changed files with 47 additions and 5 deletions

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# Run with: zsh -df plugins/timer/tests/timer.test.zsh
emulate -L zsh
source "${0:A:h:h}/timer.plugin.zsh"
typeset -i failures=0 tests=0
check_duration() {
local precision=$1 duration=$2 expected=$3
local output=$(TIMER_PRECISION=$precision __timer_format_duration $duration)
(( tests++ ))
if [[ $output == "$expected" ]]; then
print -r -- "PASS: $duration with precision $precision -> $output"
else
print -u2 -r -- "FAIL: $duration with precision $precision -> $output (expected $expected)"
(( failures++ ))
fi
}
check_duration 1 0.04 /0.0s
check_duration 1 3.04 /3.0s
check_duration 1 40.0 /40.0s
check_duration 1 59.94 /59.9s
check_duration 1 59.97 /1m0.0s
check_duration 1 61.5 /1m1.5s
check_duration 1 73.0 /1m13.0s
check_duration 1 119.97 /2m0.0s
check_duration 1 3599.99 /60m0.0s
check_duration 2 59.996 /1m0.00s
check_duration 2 0.02 /0.02s
check_duration 0 1.4 /1s
check_duration 0 59.6 /1m0s
check_duration 0 119.5 /2m0s
print -r -- "$tests tests, $failures failures"
(( failures == 0 ))
+8 -2
View File
@@ -6,8 +6,14 @@ __timer_current_time() {
}
__timer_format_duration() {
local mins=$(printf '%.0f' $(($(IFS='.' read int dec <<< "$1"; echo $int) / 60)))
local secs=$(printf "%.${TIMER_PRECISION:-1}f" $(($1 - 60 * mins)))
local -i precision=${TIMER_PRECISION:-1}
local -i scale=$(( 10 ** precision ))
# Round to the displayed precision before splitting off the minutes,
# so that e.g. 59.97s is shown as 1m0.0s instead of 60.0s
local -i units
(( units = $1 * scale + 0.5 ))
local -i mins=$(( units / (60 * scale) ))
local secs=$(printf "%.${precision}f" $(( (units - 60 * scale * mins) / (scale * 1.0) )))
local duration_str=$(echo "${mins}m${secs}s")
local format="${TIMER_FORMAT:-/%d}"
echo "${format//\%d/${duration_str#0m}}"
-1
View File
@@ -43,7 +43,6 @@ Available search contexts are:
| `wolframalpha` | `https://wolframalpha.com/input?i=` |
| `archive` | `https://web.archive.org/web/*/` |
| `scholar` | `https://scholar.google.com/scholar?q=` |
| `ask` | `https://www.ask.com/web?q=` |
| `youtube` | `https://www.youtube.com/results?search_query=` |
| `deepl` | `https://www.deepl.com/translator#auto/auto/` |
| `dockerhub` | `https://hub.docker.com/search?q=` |
-2
View File
@@ -24,7 +24,6 @@ function web_search() {
wolframalpha "https://www.wolframalpha.com/input/?i="
archive "https://web.archive.org/web/*/"
scholar "https://scholar.google.com/scholar?q="
ask "https://www.ask.com/web?q="
youtube "https://www.youtube.com/results?search_query="
deepl "https://www.deepl.com/translator#auto/auto/"
dockerhub "https://hub.docker.com/search?q="
@@ -89,7 +88,6 @@ alias stackoverflow='web_search stackoverflow'
alias wolframalpha='web_search wolframalpha'
alias archive='web_search archive'
alias scholar='web_search scholar'
alias ask='web_search ask'
alias youtube='web_search youtube'
alias deepl='web_search deepl'
alias dockerhub='web_search dockerhub'