Class: RubyLLM::Toolbox::Tools::DateTime

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_llm/toolbox/tools/date_time.rb

Overview

SAFE. Reports the current date/time (or converts a given unix timestamp), with optional strftime formatting.

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#call, exec_tool!, exec_tool?, #initialize, #name

Constructor Details

This class inherits a constructor from RubyLLM::Toolbox::Base

Instance Method Details

#execute(format: nil, unix: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ruby_llm/toolbox/tools/date_time.rb', line 22

def execute(format: nil, unix: nil)
  time = unix.nil? ? Time.now : Time.at(unix.to_i).utc

  if format && !format.to_s.strip.empty?
    return time.strftime(format.to_s)
  end

  [
    "iso8601: #{time.iso8601}",
    "unix: #{time.to_i}",
    "date: #{time.strftime('%A, %B %-d, %Y')}",
    "time: #{time.strftime('%H:%M:%S')}",
    "timezone: #{time.strftime('%Z (%z)')}"
  ].join("\n")
rescue StandardError => e
  error("could not format time: #{e.message}", code: :bad_format)
end