mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 14:11:29 +00:00
Fix (again) the Windows date representation problem.
This commit is contained in:
@@ -42,24 +42,26 @@ function record_skew(host, timestamp, received)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Work around Windows error formatting time zones where 1970/1/1 UTC was 1969/12/31
|
-- Work around Windows error formatting time zones where 1970/1/1 UTC was 1969/12/31
|
||||||
system_time_at_epoch = (
|
local utc_offset_seconds
|
||||||
time({year=1970, month=1, day=2, hour=0}) -- local time on 1970/1/2
|
do
|
||||||
- 86400 -- minus 1 day = local time at 1970/1/1
|
|
||||||
- time(date("!*t", 0)) -- minus UTC offset (Windows). On *nix this is 0.
|
|
||||||
)
|
|
||||||
-- Find the offset in seconds between local time and UTC. That is, if we
|
|
||||||
-- interpret a UTC date table as a local date table by passing it to os.time,
|
|
||||||
-- how much must be added to the resulting integer timestamp to make it
|
|
||||||
-- correct?
|
|
||||||
local function utc_offset(t)
|
|
||||||
-- What does the calendar say locally?
|
-- What does the calendar say locally?
|
||||||
local localtime = date("*t", t)
|
local localtime = date("*t", 86400)
|
||||||
-- What does the calendar say in UTC?
|
-- What does the calendar say in UTC?
|
||||||
local gmtime = date("!*t", t)
|
local gmtime = date("!*t", 86400)
|
||||||
-- Interpret both as local calendar dates and find the difference.
|
-- Interpret both as local calendar dates and find the difference.
|
||||||
return difftime(time(localtime), time(gmtime))
|
utc_offset_seconds = difftime(time(localtime), time(gmtime))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- The offset in seconds between local time and UTC.
|
||||||
|
--
|
||||||
|
-- That is, if we interpret a UTC date table as a local date table by passing
|
||||||
|
-- it to os.time, how much must be added to the resulting integer timestamp to
|
||||||
|
-- make it correct?
|
||||||
|
--
|
||||||
|
-- In other words, subtract this value from a timestamp if you intend to use it
|
||||||
|
-- in os.date.
|
||||||
|
function utc_offset() return utc_offset_seconds end
|
||||||
|
|
||||||
--- Convert a date table into an integer timestamp.
|
--- Convert a date table into an integer timestamp.
|
||||||
--
|
--
|
||||||
-- Unlike os.time, this does not assume that the date table represents a local
|
-- Unlike os.time, this does not assume that the date table represents a local
|
||||||
@@ -83,7 +85,7 @@ function date_to_timestamp(date_t, offset)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
offset = offset or 0
|
offset = offset or 0
|
||||||
return tm + utc_offset(tm) - offset
|
return tm + utc_offset() - offset
|
||||||
end
|
end
|
||||||
|
|
||||||
local function format_tz(offset)
|
local function format_tz(offset)
|
||||||
@@ -140,7 +142,7 @@ function format_timestamp(t, offset)
|
|||||||
if tmp > 0xffffffff then
|
if tmp > 0xffffffff then
|
||||||
-- Maybe too far in the future?
|
-- Maybe too far in the future?
|
||||||
extra_years = (tmp - 0xffffffff) // seconds_in_year + 1
|
extra_years = (tmp - 0xffffffff) // seconds_in_year + 1
|
||||||
elseif tmp < system_time_at_epoch then
|
elseif tmp < -utc_offset() then
|
||||||
-- Windows can't display times before the epoch
|
-- Windows can't display times before the epoch
|
||||||
extra_years = tmp // seconds_in_year
|
extra_years = tmp // seconds_in_year
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -825,7 +825,7 @@ function convertADTimeStamp(timestamp)
|
|||||||
local result = 0
|
local result = 0
|
||||||
-- Windows cannot represent this time, so we pre-calculated it:
|
-- Windows cannot represent this time, so we pre-calculated it:
|
||||||
-- seconds since 1601/1/1 adjusted for local offset
|
-- seconds since 1601/1/1 adjusted for local offset
|
||||||
local base_time = -11644473600 + datetime.system_time_at_epoch
|
local base_time = -11644473600 - datetime.utc_offset()
|
||||||
|
|
||||||
timestamp = tonumber(timestamp)
|
timestamp = tonumber(timestamp)
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- This constant is number of seconds from 1900-01-01 to 1970-01-01
|
-- This constant is number of seconds from 1900-01-01 to 1970-01-01
|
||||||
local tds_offset_seconds = -2208988800 + datetime.system_time_at_epoch
|
local tds_offset_seconds = -2208988800 - datetime.utc_offset()
|
||||||
|
|
||||||
-- *************************************
|
-- *************************************
|
||||||
-- Informational Classes
|
-- Informational Classes
|
||||||
|
|||||||
Reference in New Issue
Block a user