--- utils/osmosis-db_replag~	2025-05-17 15:19:08
+++ utils/osmosis-db_replag	2025-05-17 15:18:20
@@ -15,15 +15,27 @@
 # You should have received a copy of the GNU General Public License
 # along with this program; If not, see http://www.gnu.org/licenses/.
 
-STATE=/var/cache/renderd/tiles/.osmosis/state.txt
+STATE=@PREFIX@/var/lib/mod_tile/.osmosis/state.txt
 
-rep=$(cat ${STATE} |
-  grep 'timestamp' |
-  awk '{split($0, a, "="); print a[2]}' |
-  tr 'T' ' ' |
-  xargs -I{} ${BINPATH}date --utc --date "{}" +%s)
-is=$(date --utc +%s)
+if [ ! -r "$STATE" ]; then
+  echo "-1 seconds"
+  exit 0
+fi
 
+if [[ "$OSTYPE" != "darwin"* ]]; then
+  rep=$(cat ${STATE} |
+    grep 'timestamp' |
+    awk '{split($0, a, "="); print a[2]}' |
+    tr 'T' ' ' |
+    xargs -I{} ${BINPATH}date --utc --date "{}" +%s)
+  is=$(date -u +%s)
+else
+  rep=$(cat ${STATE} |\
+    awk '/timestamp=/{d = substr($1, 11, 10);t = substr($1, 22, 10); z = substr($1, 32); if (z = "Z") {z = "UTC";}; print d " " t z;}' |\
+    xargs -I{} ${BINPATH}date -ju -f "%Y-%m-%d %H:%M:%S%Z" "{}" +%s)
+  is=$(date -u +%s)
+fi
+
 lag=$(($is - $rep))
 
 if [ "$1" = "-h" ]; then
