What it does
The handler accepts an empty JSON object and rejects unexpected arguments. Its result includes an ISO 8601 local time with a numeric UTC offset. A Windows time-zone ID containing Standard Time is not a substitute for that actual offset.
Watch this version
Read the implementation
This page describes the selected release. The source link points to the same exact commit; it cannot silently open a newer implementation.
Lilith/Core/Tools/CurrentTimeTool.cs ↗Implementation code
Read the implementation from this version's exact source snapshot. Helper links below stay on the same release.
Lilith/Core/Tools/CurrentTimeTool.cs
C#
using System.Text.Json;
namespace Lilith.Core.Tools;
public sealed class CurrentTimeTool : ILilithTool
{
public string Name => "get_current_time";
public string Description => "Get the current date and time on this computer, including its time zone and UTC time.";
public JsonElement Parameters => JsonSerializer.SerializeToElement(new
{
type = "object", properties = new { }, additionalProperties = false
});
public Task<string> ExecuteAsync(JsonElement arguments, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
if (arguments.ValueKind != JsonValueKind.Object || arguments.EnumerateObject().Any())
throw new ArgumentException("get_current_time expects an empty argument object.");
var now = DateTimeOffset.UtcNow;
return Task.FromResult(JsonSerializer.Serialize(new
{
local_time = TimeZoneInfo.ConvertTime(now, TimeZoneInfo.Local).ToString("O"),
utc_time = now.ToString("O"), time_zone = TimeZoneInfo.Local.Id
}));
}
}