mirror of
https://github.com/Evolix/chexpire.git
synced 2024-05-05 02:05:09 +02:00
Whois: Time in UTC instead of DateTime
This commit is contained in:
parent
79165fb5b8
commit
53fb0d38de
|
@ -47,7 +47,7 @@ module Whois
|
|||
fail MissingDateFormatError, "Date format not set" if date_format.nil?
|
||||
|
||||
begin
|
||||
Date.strptime(str, date_format)
|
||||
Time.strptime(str, date_format)
|
||||
rescue ArgumentError
|
||||
raise InvalidDateError, "Date `#{str}` does not match format #{date_format}"
|
||||
end
|
||||
|
|
|
@ -19,21 +19,25 @@ module Whois::Parser
|
|||
domain_index = get_field!("domain", value: domain).index
|
||||
|
||||
created_date = get_value!("created", after: domain_index)
|
||||
response.created_on = parse_date(created_date)
|
||||
response.created_at = parse_date(created_date)
|
||||
|
||||
expire_date = get_value!("Expiry Date", after: domain_index)
|
||||
response.expire_on = parse_date(expire_date)
|
||||
response.expire_at = parse_date(expire_date)
|
||||
|
||||
updated_date = get_value!("last-update", after: domain_index)
|
||||
response.updated_on = parse_date(updated_date)
|
||||
response.updated_at = parse_date(updated_date)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_date(str)
|
||||
super "#{str} UTC"
|
||||
end
|
||||
|
||||
def set_date_format
|
||||
afnic_format = get_field!("complete date format").value
|
||||
|
||||
@date_format = "%d/%m/%Y" if afnic_format == "DD/MM/YYYY"
|
||||
@date_format = "%d/%m/%Y %Z" if afnic_format == "DD/MM/YYYY"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module Whois
|
||||
class Response
|
||||
attr_accessor :created_on
|
||||
attr_accessor :updated_on
|
||||
attr_accessor :expire_on
|
||||
attr_accessor :created_at
|
||||
attr_accessor :updated_at
|
||||
attr_accessor :expire_at
|
||||
|
||||
def initialize(domain)
|
||||
@domain = domain
|
||||
|
|
|
@ -13,9 +13,11 @@ module Whois
|
|||
response = @parser.parse(@domain_fr)
|
||||
assert_kind_of Response, response
|
||||
|
||||
assert_equal Date.new(2004, 2, 18), response.created_on
|
||||
assert_equal Date.new(2017, 1, 28), response.updated_on
|
||||
assert_equal Date.new(2019, 2, 17), response.expire_on
|
||||
assert_equal Time.new(2004, 2, 18, 0, 0, 0, 0), response.created_at
|
||||
assert response.created_at.utc?
|
||||
|
||||
assert_equal Time.new(2017, 1, 28, 0, 0, 0, 0), response.updated_at
|
||||
assert_equal Time.new(2019, 2, 17, 0, 0, 0, 0), response.expire_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue