Skip to content

Commit f3f580c

Browse files
committed
Fix uptime calculation regression on Ubuntu 24 (preserve Z for UTC parsing)
1 parent d14b7c7 commit f3f580c

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

mtproxymax.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,14 +2539,16 @@ restart_proxy_container() {
25392539
_iso_to_epoch() {
25402540
local ts="$1"
25412541
[ -z "$ts" ] && { echo "0"; return; }
2542-
# Strip sub-second precision and trailing Z (e.g. 2026-03-03T10:00:00.123456789Z -> 2026-03-03T10:00:00)
2543-
ts="${ts%%.*}"
2544-
ts="${ts%%Z}"
2545-
# GNU date: date -d "..." +%s
2542+
# Strip sub-second precision only, keep Z for UTC (e.g. 2026-03-03T10:00:00.123456789Z -> 2026-03-03T10:00:00Z)
2543+
local ts_clean="${ts%%.*}"
2544+
# Restore trailing Z if original had it
2545+
[[ "$ts" == *Z ]] && ts_clean="${ts_clean}Z"
25462546
local epoch
2547-
epoch=$(date -d "${ts}" +%s 2>/dev/null) && { echo "$epoch"; return; }
2548-
# Busybox date: date -D '%Y-%m-%dT%H:%M:%S' -d "..." +%s
2549-
epoch=$(date -D '%Y-%m-%dT%H:%M:%S' -d "${ts}" +%s 2>/dev/null) && { echo "$epoch"; return; }
2547+
# GNU date: handles ISO 8601 with Z correctly
2548+
epoch=$(date -d "${ts_clean}" +%s 2>/dev/null) && [ "$epoch" -gt 0 ] 2>/dev/null && { echo "$epoch"; return; }
2549+
# Busybox date: strip Z, use explicit format
2550+
local ts_bb="${ts_clean%Z}"
2551+
epoch=$(date -D '%Y-%m-%dT%H:%M:%S' -d "${ts_bb}" +%s 2>/dev/null) && [ "$epoch" -gt 0 ] 2>/dev/null && { echo "$epoch"; return; }
25502552
echo "0"
25512553
}
25522554

@@ -3390,10 +3392,13 @@ get_stats() {
33903392
get_uptime() {
33913393
local sa=$(docker inspect --format '{{.State.StartedAt}}' mtproxymax 2>/dev/null)
33923394
[ -z "$sa" ] && echo 0 && return
3393-
# Portable ISO 8601 -> epoch (GNU date, busybox date)
3394-
sa="${sa%%.*}"; sa="${sa%%Z}"
3395+
local sa_clean="${sa%%.*}"
3396+
[[ "$sa" == *Z ]] && sa_clean="${sa_clean}Z"
33953397
local se
3396-
se=$(date -d "$sa" +%s 2>/dev/null) || se=$(date -D '%Y-%m-%dT%H:%M:%S' -d "$sa" +%s 2>/dev/null) || se=0
3398+
se=$(date -d "$sa_clean" +%s 2>/dev/null) && [ "$se" -gt 0 ] 2>/dev/null || {
3399+
local sa_bb="${sa_clean%Z}"
3400+
se=$(date -D '%Y-%m-%dT%H:%M:%S' -d "$sa_bb" +%s 2>/dev/null) || se=0
3401+
}
33973402
echo $(( $(date +%s) - se ))
33983403
}
33993404

0 commit comments

Comments
 (0)