From 8eae2e192a453d0477189d9ef88d70f4ac2fa23f Mon Sep 17 00:00:00 2001 From: Madhusudhan Date: Fri, 24 Oct 2025 13:30:22 +0530 Subject: [PATCH] fix: re-implement get_today using chrono as the previous implementation was giving wrong date --- shai-core/src/runners/coder/env.rs | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/shai-core/src/runners/coder/env.rs b/shai-core/src/runners/coder/env.rs index 197a56d..aa25f0b 100644 --- a/shai-core/src/runners/coder/env.rs +++ b/shai-core/src/runners/coder/env.rs @@ -91,35 +91,9 @@ pub fn get_os_version() -> String { /// Get today's date in YYYY-MM-DD format pub fn get_today() -> String { - use std::time::{SystemTime, UNIX_EPOCH}; + use chrono::Local; - let now = SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_secs(); - - // Simple date calculation (days since Unix epoch) - let days = now / 86400; - let (year, month, day) = days_to_ymd(days as i32); - - format!("{:04}-{:02}-{:02}", year, month, day) -} - -// Helper function to convert days since Unix epoch to year/month/day -fn days_to_ymd(days: i32) -> (i32, i32, i32) { - let days = days + 719163; // Adjust for Unix epoch (1970-01-01) - - let era = days / 146097; - let doe = days % 146097; - let yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365; - let year = yoe + era * 400; - let doy = doe - (365*yoe + yoe/4 - yoe/100); - let mp = (5*doy + 2) / 153; - let day = doy - (153*mp + 2) / 5 + 1; - let month = mp + if mp < 10 { 3 } else { -9 }; - let year = year + if month <= 2 { 1 } else { 0 }; - - (year, month, day) + Local::now().date_naive().format("%Y-%m-%d").to_string() } /// Get the current git branch