Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/ninety-candles-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"roo-cline": patch
---

Add the current time to the system prompt
16 changes: 16 additions & 0 deletions src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2462,6 +2462,22 @@ export class Cline {
details += terminalDetails
}

// 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 timeZoneOffsetStr = `${timeZoneOffset >= 0 ? '+' : ''}${timeZoneOffset}:00`
details += `\n\n# Current Time\n${formatter.format(now)} (${timeZone}, UTC${timeZoneOffsetStr})`

if (includeFileDetails) {
details += `\n\n# Current Working Directory (${cwd.toPosix()}) Files\n`
const isDesktop = arePathsEqual(cwd, path.join(os.homedir(), "Desktop"))
Expand Down
64 changes: 64 additions & 0 deletions src/core/__tests__/Cline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,68 @@ describe('Cline', () => {
}).toThrow('Either historyItem or task/images must be provided');
});
});

describe('getEnvironmentDetails', () => {
let originalDate: DateConstructor;
let mockDate: Date;

beforeEach(() => {
originalDate = global.Date;
const fixedTime = new Date('2024-01-01T12:00:00Z');
mockDate = new Date(fixedTime);
mockDate.getTimezoneOffset = jest.fn().mockReturnValue(420); // UTC-7

class MockDate extends Date {
constructor() {
super();
return mockDate;
}
static override now() {
return mockDate.getTime();
}
}

global.Date = MockDate as DateConstructor;

// Create a proper mock of Intl.DateTimeFormat
const mockDateTimeFormat = {
resolvedOptions: () => ({
timeZone: 'America/Los_Angeles'
}),
format: () => '1/1/2024, 5:00:00 AM'
};

const MockDateTimeFormat = function(this: any) {
return mockDateTimeFormat;
} as any;

MockDateTimeFormat.prototype = mockDateTimeFormat;
MockDateTimeFormat.supportedLocalesOf = jest.fn().mockReturnValue(['en-US']);

global.Intl.DateTimeFormat = MockDateTimeFormat;
});

afterEach(() => {
global.Date = originalDate;
});

it('should include timezone information in environment details', async () => {
const cline = new Cline(
mockProvider,
mockApiConfig,
undefined,
false,
undefined,
'test task'
);

const details = await cline['getEnvironmentDetails'](false);

// Verify timezone information is present and formatted correctly
expect(details).toContain('America/Los_Angeles');
expect(details).toMatch(/UTC-7:00/); // Fixed offset for America/Los_Angeles
expect(details).toContain('# Current Time');
expect(details).toMatch(/1\/1\/2024.*5:00:00 AM.*\(America\/Los_Angeles, UTC-7:00\)/); // Full time string format
});
});
});
Loading