Class: SharedTools::Tools::CurrentDateTimeTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::CurrentDateTimeTool
- Defined in:
- lib/shared_tools/tools/current_date_time_tool.rb
Overview
Returns the current date, time, and timezone from the local system.
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(format: 'full') ⇒ Hash
Date/time information.
-
#initialize(logger: nil) ⇒ CurrentDateTimeTool
constructor
A new instance of CurrentDateTimeTool.
Constructor Details
#initialize(logger: nil) ⇒ CurrentDateTimeTool
Returns a new instance of CurrentDateTimeTool.
34 35 36 |
# File 'lib/shared_tools/tools/current_date_time_tool.rb', line 34 def initialize(logger: nil) @logger = logger || RubyLLM.logger end |
Class Method Details
.name ⇒ Object
15 |
# File 'lib/shared_tools/tools/current_date_time_tool.rb', line 15 def self.name = 'current_date_time_tool' |
Instance Method Details
#execute(format: 'full') ⇒ Hash
Returns date/time information.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/shared_tools/tools/current_date_time_tool.rb', line 40 def execute(format: 'full') @logger.info("CurrentDateTimeTool#execute format=#{format}") now = Time.now utc = now.utc date_info = { year: now.year, month: now.month, day: now.day, day_of_week: now.strftime('%A'), day_of_week_num: now.wday, week_of_year: now.strftime('%U').to_i, quarter: ((now.month - 1) / 3) + 1, ordinal_day: now.yday } time_info = { hour: now.hour, minute: now.min, second: now.sec, timezone: now.zone, utc_offset: now.strftime('%z'), utc_offset_hours: (now.utc_offset / 3600.0).round(2) } iso_info = { iso8601: now.iso8601, iso8601_utc: utc.iso8601, unix_timestamp: now.to_i } case format.to_s.downcase when 'date' { success: true }.merge(date_info) when 'time' { success: true }.merge(time_info) when 'iso8601' { success: true }.merge(iso_info) else { success: true, dst: now.dst? } .merge(date_info) .merge(time_info) .merge(iso_info) end end |