ruby/ruby · error · ArgumentError
no time information in #{date.inspect}
Error message
no time information in #{date.inspect} What it means
Time.parse feeds the string to Date._parse and passes the fragments to make_time. If every temporal component is nil (no year, yday, mon, day, hour, min, sec, or sec_fraction was recognized), it cannot construct any Time and raises ArgumentError 'no time information in <string.inspect>'. A string yielding only a zone name is not enough.
Source
Thrown at lib/time.rb:203
if off != 0 then
day -= off
if day < 1
mon -= 1
if mon < 1
year -= 1
mon = 12
end
day = month_days(year, mon)
end
end
end
return year, mon, day, hour, min, sec
end
private :apply_offset
def make_time(date, year, yday, mon, day, hour, min, sec, sec_fraction, zone, now)
if !year && !yday && !mon && !day && !hour && !min && !sec && !sec_fraction
raise ArgumentError, "no time information in #{date.inspect}"
end
off = nil
if year || now
off_year = year || now.year
off = zone_offset(zone, off_year) if zone
end
if yday
unless (1..366) === yday
raise ArgumentError, "yday #{yday} out of range"
end
mon, day = (yday-1).divmod(31)
mon += 1
day += 1
t = make_time(date, year, nil, mon, day, hour, min, sec, sec_fraction, zone, now)
diff = yday - t.yday
return t if diff.zero?View on GitHub (pinned to 0e5b888e1c)
Solutions
- Pre-check recognition: Date._parse(str) and require a real component (e.g. :year, :mday, or :hour) before calling Time.parse
- Rescue ArgumentError and use a fallback (nil or Time.now) with a targeted rescue, not a blanket one
- Use a strict format when you control the input: Time.strptime(str, '%Y-%m-%d %H:%M:%S')
- Fix the upstream extraction so the date substring actually reaches the parser
Example fix
# before ts = Time.parse(line) # free-text line with no date -> raises # after frag = Date._parse(line) ts = (frag[:year] || frag[:mday] || frag[:hour]) ? Time.parse(line) : nil
Defensive patterns
Strategy: validation
Validate before calling
frag = Date._parse(candidate)
has_time = frag.slice(:year, :mday, :hour, :min, :sec).any? { |_, v| v }
ts = has_time ? Time.parse(candidate) : nil Try / catch
begin Time.parse(candidate) rescue ArgumentError nil # or fallback_time end
Prevention
- Require 'time' and pre-screen free text with Date._parse
- Use strptime with an explicit format for machine-generated input
- Blank-string inputs are not dates: validate presence first
When it happens
Trigger: Time.parse(""); Time.parse("hello world"); Time.parse("UTC") (zone only); Time.parse(nil) goes through a different coercion; parsing a free-text field that happens to contain no recognizable date.
Common situations: Log lines whose date sits on a previous line; optional config/env fields that are blank; scraping where the selector grabbed the wrong element; user-entered notes fed into Time.parse.
Related errors
- yday #{yday} out of range
- invalid date or strptime format - '#{date}' '#{format}'
- timezone argument given as positional and keyword arguments
- end of file reached
- OpenSSL::PKey::DH is immutable on OpenSSL 3.0; use OpenSSL::
AI-assisted analysis of ruby/ruby@0e5b888e1c (2026-08-21).
Data as JSON: /api/errors/97e5bee708b0a43b.
Report an issue: GitHub.