Skip to content

Commit 8eae2e1

Browse files
fix: re-implement get_today using chrono as the previous implementation was giving wrong date
1 parent eda106e commit 8eae2e1

File tree

1 file changed

+2
-28
lines changed
  • shai-core/src/runners/coder

1 file changed

+2
-28
lines changed

shai-core/src/runners/coder/env.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,35 +91,9 @@ pub fn get_os_version() -> String {
9191

9292
/// Get today's date in YYYY-MM-DD format
9393
pub fn get_today() -> String {
94-
use std::time::{SystemTime, UNIX_EPOCH};
94+
use chrono::Local;
9595

96-
let now = SystemTime::now()
97-
.duration_since(UNIX_EPOCH)
98-
.unwrap()
99-
.as_secs();
100-
101-
// Simple date calculation (days since Unix epoch)
102-
let days = now / 86400;
103-
let (year, month, day) = days_to_ymd(days as i32);
104-
105-
format!("{:04}-{:02}-{:02}", year, month, day)
106-
}
107-
108-
// Helper function to convert days since Unix epoch to year/month/day
109-
fn days_to_ymd(days: i32) -> (i32, i32, i32) {
110-
let days = days + 719163; // Adjust for Unix epoch (1970-01-01)
111-
112-
let era = days / 146097;
113-
let doe = days % 146097;
114-
let yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365;
115-
let year = yoe + era * 400;
116-
let doy = doe - (365*yoe + yoe/4 - yoe/100);
117-
let mp = (5*doy + 2) / 153;
118-
let day = doy - (153*mp + 2) / 5 + 1;
119-
let month = mp + if mp < 10 { 3 } else { -9 };
120-
let year = year + if month <= 2 { 1 } else { 0 };
121-
122-
(year, month, day)
96+
Local::now().date_naive().format("%Y-%m-%d").to_string()
12397
}
12498

12599
/// Get the current git branch

0 commit comments

Comments
 (0)