From 125d84fd6705f957a4d3922a43cf273bdb0adf79 Mon Sep 17 00:00:00 2001 From: dmiller Date: Wed, 21 May 2014 15:04:12 +0000 Subject: [PATCH] Allow stdnse.format_timestamp to take a Lua date table This will allow formatting of timestamps beyond 2036, which currently are limited by the wrapping of the 32-bit Unix timestamp. --- nselib/stdnse.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua index 32acc88df..7e085d626 100644 --- a/nselib/stdnse.lua +++ b/nselib/stdnse.lua @@ -446,9 +446,16 @@ end -- This function should be used for all dates emitted as part of NSE structured -- output. function format_timestamp(t, offset) - local tz_string = format_tz(offset) - offset = offset or 0 - return os.date("!%Y-%m-%dT%H:%M:%S", t + offset) .. tz_string + if type(t) == "table" then + return string.format( + "%d-%02d-%02dT%02d:%02d:%02d", + t.year, t.month, t.day, t.hour, t.min, t.sec + ) + else + local tz_string = format_tz(offset) + offset = offset or 0 + return os.date("!%Y-%m-%dT%H:%M:%S", t + offset) .. tz_string + end end --- Format the difference between times t2 and t1