From 391b86d1a31be945076d8def79bf8d7ec939f486 Mon Sep 17 00:00:00 2001 From: Sebastian Englbrecht Date: Sun, 15 Feb 2026 17:19:33 +0100 Subject: [PATCH] feat: make date busybox compatible --- index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0025f92..1b66b3d 100644 --- a/index.js +++ b/index.js @@ -67,11 +67,16 @@ module.exports = function (app) { logError(lastMessage) return } + const parsedDate = new Date(datetime) + if (Number.isNaN(parsedDate.getTime())) { + lastMessage = 'Invalid datetime value received: ' + String(datetime).substring(0, 50) + logError(lastMessage) + return + } const useSudoFallback = typeof options.sudo === 'undefined' || options.sudo - // Convert ISO 8601 datetime to format compatible with both GNU date and BusyBox date - // e.g., "2024-01-10T17:55:03.000Z" → "2024-01-10 17:55:03" - const dateStr = datetime.replace('T', ' ').replace(/\.\d+Z?$|Z$/, '') - const setDate = `date -u -s "${dateStr}"` + // Use epoch seconds to avoid BusyBox date format incompatibilities + const epochSeconds = Math.floor(parsedDate.getTime() / 1000) + const setDate = `date -u -s "@${epochSeconds}"` // First try without sudo (works in Docker with setuid bit on /usr/bin/date) child = require('child_process').spawn('sh', ['-c', setDate])