From d0c725ae4e23d0b0ee54bc8e10639f9c2de5a9be Mon Sep 17 00:00:00 2001 From: Helmi Date: Sun, 6 Apr 2025 19:04:46 +0200 Subject: [PATCH] Switched Datetime format for to something clearer (ISO) --- src/core/Cline.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 7f5ef949da3..9d25ab24c7a 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -2259,21 +2259,18 @@ export class Cline extends EventEmitter { // Add current time information with timezone const now = new Date() - const formatter = new Intl.DateTimeFormat(undefined, { - year: "numeric", - month: "numeric", - day: "numeric", - hour: "numeric", - minute: "numeric", - second: "numeric", - hour12: true, - }) - const timeZone = formatter.resolvedOptions().timeZone - const timeZoneOffset = -now.getTimezoneOffset() / 60 // Convert to hours and invert sign to match conventional notation - const timeZoneOffsetHours = Math.floor(Math.abs(timeZoneOffset)) - const timeZoneOffsetMinutes = Math.abs(Math.round((Math.abs(timeZoneOffset) - timeZoneOffsetHours) * 60)) - const timeZoneOffsetStr = `${timeZoneOffset >= 0 ? "+" : "-"}${timeZoneOffsetHours}:${timeZoneOffsetMinutes.toString().padStart(2, "0")}` - details += `\n\n# Current Time\n${formatter.format(now)} (${timeZone}, UTC${timeZoneOffsetStr})` + // Calculate timezone offset + const tzOffset = -now.getTimezoneOffset() // in minutes + const sign = tzOffset >= 0 ? "+" : "-" + const pad = (num: number) => String(Math.floor(Math.abs(num))).padStart(2, "0") + const offsetHours = pad(tzOffset / 60) + const offsetMinutes = pad(tzOffset % 60) + + // Remove the trailing 'Z' from ISO string and add the custom offset + const isoWithoutZ = now.toISOString().replace("Z", "") + const isoString = `${isoWithoutZ}${sign}${offsetHours}:${offsetMinutes}` + + details += `\n\n# Current Time\n${isoString}` // Add context tokens information const { contextTokens, totalCost } = getApiMetrics(this.clineMessages)