Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2259,21 +2259,18 @@ export class Cline extends EventEmitter<ClineEvents> {

// 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", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new implementation for formatting the current time is problematic: it uses now.toISOString() (which always returns a UTC timestamp) and then simply removes the trailing 'Z' and appends the local timezone offset. This does not convert the time portion to local time. For example, in a timezone of UTC+01:00, if the real local time is 12:00, toISOString() might yield 11:00Z, and the result becomes "11:00+01:00" instead of the correct local time 12:00. Consider converting the date to local values (using native Date methods or a date library) before formatting, so the time and offset are consistent. This issue should be fixed to reliably display the correct local time.

const isoString = `${isoWithoutZ}${sign}${offsetHours}:${offsetMinutes}`

details += `\n\n# Current Time\n${isoString}`

// Add context tokens information
const { contextTokens, totalCost } = getApiMetrics(this.clineMessages)
Expand Down
Loading