"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "nselib/datetime.lua" between
nmap-7.90.tgz and nmap-7.91.tgz

About: Nmap ("Network Mapper") is a utility for network exploration or security auditing (port scanner).

datetime.lua  (nmap-7.90.tgz):datetime.lua  (nmap-7.91.tgz)
skipping to change at line 44 skipping to change at line 44
local skew_tab = host.registry.datetime_skew local skew_tab = host.registry.datetime_skew
skew_tab = skew_tab or {} skew_tab = skew_tab or {}
-- No srtt? I suppose we'll ignore it, but this could cause problems -- No srtt? I suppose we'll ignore it, but this could cause problems
local srtt = host.times and host.times.srtt or 0 local srtt = host.times and host.times.srtt or 0
local adjusted = difftime(floor(timestamp), floor(received)) - srtt / 2.0 local adjusted = difftime(floor(timestamp), floor(received)) - srtt / 2.0
skew_tab[#skew_tab + 1] = adjusted skew_tab[#skew_tab + 1] = adjusted
stdnse.debug2("record_skew: %s", adjusted) stdnse.debug2("record_skew: %s", adjusted)
host.registry.datetime_skew = skew_tab host.registry.datetime_skew = skew_tab
end end
local function utc_offset(t) -- Work around Windows error formatting time zones where 1970/1/1 UTC was 1969/1
2/31
local utc_offset_seconds
do
-- 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
-- time. Rather, it takes an optional offset number of seconds representing the -- time. Rather, it takes an optional offset number of seconds representing the
-- time zone, and returns the timestamp that would result using that time zone -- time zone, and returns the timestamp that would result using that time zone
-- as local time. If the offset is omitted or 0, the date table is interpreted -- as local time. If the offset is omitted or 0, the date table is interpreted
-- as a UTC date. For example, 4:00 UTC is the same as 5:00 UTC+1: -- as a UTC date. For example, 4:00 UTC is the same as 5:00 UTC+1:
-- <code> -- <code>
-- date_to_timestamp({year=1970,month=1,day=1,hour=4,min=0,sec=0}) --> 14400 -- date_to_timestamp({year=1970,month=1,day=1,hour=4,min=0,sec=0}) --> 14400
-- date_to_timestamp({year=1970,month=1,day=1,hour=4,min=0,sec=0}, 0) --> 14400 -- date_to_timestamp({year=1970,month=1,day=1,hour=4,min=0,sec=0}, 0) --> 14400
-- date_to_timestamp({year=1970,month=1,day=1,hour=5,min=0,sec=0}, 1*60*60) --> 14400 -- date_to_timestamp({year=1970,month=1,day=1,hour=5,min=0,sec=0}, 1*60*60) --> 14400
-- </code> -- </code>
-- And 4:00 UTC+1 is an earlier time: -- And 4:00 UTC+1 is an earlier time:
-- <code> -- <code>
-- date_to_timestamp({year=1970,month=1,day=1,hour=4,min=0,sec=0}, 1*60*60) --> 10800 -- date_to_timestamp({year=1970,month=1,day=1,hour=4,min=0,sec=0}, 1*60*60) --> 10800
-- </code> -- </code>
function date_to_timestamp(date, offset) function date_to_timestamp(date_t, offset)
local status, tm = pcall(time, date_t)
if not status then
stdnse.debug1("Invalid date for this platform: %s", tm)
return nil
end
offset = offset or 0 offset = offset or 0
return time(date) + utc_offset(time(date)) - offset return tm + utc_offset() - offset
end end
local function format_tz(offset) local function format_tz(offset)
local sign, hh, mm local sign, hh, mm
if not offset then if not offset then
return "" return ""
end end
if offset < 0 then if offset < 0 then
sign = "-" sign = "-"
skipping to change at line 127 skipping to change at line 140
return format( return format(
"%d-%02d-%02dT%02d:%02d:%02d", "%d-%02d-%02dT%02d:%02d:%02d",
t.year, t.month, t.day, t.hour, t.min, t.sec t.year, t.month, t.day, t.hour, t.min, t.sec
) )
else else
local tz_string = format_tz(offset) local tz_string = format_tz(offset)
offset = offset or 0 offset = offset or 0
local status, result = pcall(date, "!%Y-%m-%dT%H:%M:%S", floor(t + offset)) local status, result = pcall(date, "!%Y-%m-%dT%H:%M:%S", floor(t + offset))
if not status then if not status then
local tmp = floor(t + offset) local tmp = floor(t + offset)
local extra_years
local seconds_in_year = 31556926
if tmp > 0xffffffff then if tmp > 0xffffffff then
-- Maybe too far in the future? -- Maybe too far in the future?
local seconds_in_year = 31556926 extra_years = (tmp - 0xffffffff) // seconds_in_year + 1
local extra_years = (tmp - 0xffffffff) // seconds_in_year + 1 elseif tmp < -utc_offset() then
-- Windows can't display times before the epoch
extra_years = tmp // seconds_in_year
end
if extra_years then
tmp = tmp - extra_years * seconds_in_year tmp = tmp - extra_years * seconds_in_year
status, result = pcall(date, "!*t", tmp) status, result = pcall(date, "!*t", tmp)
if status then if status then
-- seconds_in_year is imprecise, so we truncate to date only -- seconds_in_year is imprecise, so we truncate to date only
result = format("%d-%02d-%02d", result.year + extra_years, result.mont h, result.day) result = format("%d-%02d-%02d?", result.year + extra_years, result.mon th, result.day)
end end
end end
end end
if not status then if not status then
return ("Invalid timestamp: %s"):format(t) return ("Invalid timestamp: %s"):format(t)
end end
return result .. tz_string return result .. tz_string
end end
end end
 End of changes. 10 change blocks. 
9 lines changed or deleted 33 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)