Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down