From eed3d9b65c8ffa0969dfa0dfcf5580ec7d74af0d Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Sun, 14 Dec 2014 02:54:51 +0000
Subject: [PATCH] Fix @UPTIME@ to return 0 if the uptime global isn't
 initialized yet, or if time_t is unsigned and the current time is less than
 uptime.

There's comments that suggest the time(NULL) value is influenced by the
timezone, so possibly therre's a usage of it somewhere with the timezone
not being set comparing to an uptime that was set when timezone *was* set.
In this case, @UPTIME@ will say it's been up for zero days until the timezone
is set in that thread/process, or time(NULL) passes uptime.
---
 src/sbbs3/atcodes.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/sbbs3/atcodes.cpp b/src/sbbs3/atcodes.cpp
index dc954760d5..fee8372516 100644
--- a/src/sbbs3/atcodes.cpp
+++ b/src/sbbs3/atcodes.cpp
@@ -147,9 +147,10 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 
 	if(!strcmp(sp,"UPTIME")) {
 		extern volatile time_t uptime;
-		time_t up=time(NULL)-uptime;
-		if(up<0)
-			up=0;
+		time_t up=0;
+		now = time(NULL);
+		if (uptime != 0 && now >= uptime)
+			up = now-uptime;
 		char   days[64]="";
 		if((up/(24*60*60))>=2) {
 	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
-- 
GitLab