22
33use std:: path:: Path ;
44
5- use time :: OffsetDateTime ;
5+ use chrono :: Offset as _ ;
66
77use crate :: llm:: { Message , Role } ;
88use crate :: workspace;
@@ -13,6 +13,7 @@ use crate::workspace;
1313#[ allow( clippy:: too_many_arguments) ]
1414pub fn build_messages (
1515 workspace_path : & Path ,
16+ timezone : & str ,
1617 history : & [ Message ] ,
1718 summary : & str ,
1819 user_message : & str ,
@@ -23,15 +24,30 @@ pub fn build_messages(
2324) -> Vec < Message > {
2425 let mut system = String :: new ( ) ;
2526
26- // Identity: current date/time (human-readable + timezone) and Unix, workspace
27- let now = OffsetDateTime :: now_utc ( ) ;
28- let now_unix = now. unix_timestamp ( ) ;
27+ // Identity: current local date/time with UTC offset, Unix timestamp, workspace
28+ let tz: chrono_tz:: Tz = timezone
29+ . parse ( )
30+ . expect ( "timezone was validated at startup; parse cannot fail here" ) ;
31+ let now_utc = chrono:: Utc :: now ( ) ;
32+ let now_local = now_utc. with_timezone ( & tz) ;
33+ let offset_secs = now_local. offset ( ) . fix ( ) . local_minus_utc ( ) ;
34+ let offset_hours = offset_secs / 3600 ;
35+ let offset_str = if offset_hours >= 0 {
36+ format ! ( "UTC+{}" , offset_hours)
37+ } else {
38+ format ! ( "UTC{}" , offset_hours)
39+ } ;
40+ let now_unix = now_utc. timestamp ( ) ;
41+ let time_line = format ! (
42+ "Current time ({}, local): {} ({}). Unix: {}." ,
43+ offset_str,
44+ now_local. format( "%A %-d %b %Y %H:%M" ) ,
45+ timezone,
46+ now_unix,
47+ ) ;
2948 system. push_str ( "You are iCrab, a minimal personal AI assistant. " ) ;
30- system. push_str ( "Current time: " ) ;
31- system. push_str ( & format ! ( "{} {} {} UTC. " , now. weekday( ) , now. date( ) , now. time( ) ) ) ;
32- system. push_str ( "Unix: " ) ;
33- system. push_str ( & now_unix. to_string ( ) ) ;
34- system. push_str ( ". Workspace: " ) ;
49+ system. push_str ( & time_line) ;
50+ system. push_str ( " Workspace: " ) ;
3551 system. push_str ( workspace_path. to_string_lossy ( ) . as_ref ( ) ) ;
3652 system. push_str ( ".\n \n " ) ;
3753
@@ -127,6 +143,7 @@ mod tests {
127143 let workspace = std:: env:: temp_dir ( ) ;
128144 let messages = build_messages (
129145 & workspace,
146+ "Europe/London" ,
130147 & [ ] ,
131148 "" ,
132149 "hello" ,
@@ -137,12 +154,8 @@ mod tests {
137154 ) ;
138155 let system = & messages[ 0 ] . content ;
139156 assert ! (
140- system. contains( "Current time:" ) ,
141- "system prompt should include 'Current time:'"
142- ) ;
143- assert ! (
144- system. contains( " UTC." ) ,
145- "system prompt should include ' UTC.'"
157+ system. contains( "Current time (UTC" ) ,
158+ "system prompt should include 'Current time (UTC'"
146159 ) ;
147160 assert ! (
148161 system. contains( "Unix: " ) ,
0 commit comments