mirror of
https://github.com/openai/codex.git
synced 2026-04-24 22:54:54 +00:00
adding secs ago instead of start date
This commit is contained in:
@@ -4,6 +4,8 @@ use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::fs;
|
||||
use chrono::Local;
|
||||
use codex_common::elapsed::format_duration;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct TasksCli {
|
||||
@@ -148,7 +150,15 @@ fn list_tasks(args: TasksListArgs) -> anyhow::Result<()> {
|
||||
let mut branch = t.branch.clone().unwrap_or_default();
|
||||
let branch_limit = if args.all_columns { 22 } else { 22 }; // unified width
|
||||
if branch.len() > branch_limit { branch.truncate(branch_limit); }
|
||||
let start = t.start_time.map(format_epoch_short).unwrap_or_default();
|
||||
let start = t.start_time.map(|start_secs| {
|
||||
let now = Local::now().timestamp() as u64;
|
||||
if now > start_secs {
|
||||
let elapsed = std::time::Duration::from_secs(now - start_secs);
|
||||
format!("{} ago", format_duration(elapsed))
|
||||
} else {
|
||||
"just now".to_string()
|
||||
}
|
||||
}).unwrap_or_default();
|
||||
let tokens = t.total_tokens.map(|t| t.to_string()).unwrap_or_default();
|
||||
let state = t.state.clone().unwrap_or_else(|| "?".into());
|
||||
let mut model = t.model.clone().unwrap_or_default();
|
||||
@@ -167,21 +177,6 @@ fn list_tasks(args: TasksListArgs) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn format_epoch_short(secs: u64) -> String {
|
||||
use chrono::{Datelike, Local, TimeZone};
|
||||
let dt = Local.timestamp_opt(secs as i64, 0).single();
|
||||
if let Some(dt) = dt {
|
||||
let now = Local::now();
|
||||
if dt.year() == now.year() {
|
||||
dt.format("%d %b %H:%M").to_string() // e.g. 22 Jul 11:56
|
||||
} else {
|
||||
dt.format("%d %b %Y").to_string() // older year
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_default_model() -> String {
|
||||
// Attempt to read config json/yaml for model, otherwise fallback to hardcoded default.
|
||||
if let Some(base) = base_dir() {
|
||||
|
||||
@@ -22,7 +22,8 @@ fn format_elapsed_millis(millis: i64) -> String {
|
||||
if millis < 1000 {
|
||||
format!("{millis}ms")
|
||||
} else if millis < 60_000 {
|
||||
format!("{:.2}s", millis as f64 / 1000.0)
|
||||
let secs = millis / 1000;
|
||||
format!("{secs}s")
|
||||
} else {
|
||||
let minutes = millis / 60_000;
|
||||
let seconds = (millis % 60_000) / 1000;
|
||||
@@ -48,13 +49,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_format_duration_seconds() {
|
||||
// Durations between 1s (inclusive) and 60s (exclusive) should be
|
||||
// printed with 2-decimal-place seconds.
|
||||
// printed as whole seconds.
|
||||
let dur = Duration::from_millis(1_500); // 1.5s
|
||||
assert_eq!(format_duration(dur), "1.50s");
|
||||
assert_eq!(format_duration(dur), "1s");
|
||||
|
||||
// 59.999s rounds to 60.00s
|
||||
let dur2 = Duration::from_millis(59_999);
|
||||
assert_eq!(format_duration(dur2), "60.00s");
|
||||
assert_eq!(format_duration(dur2), "59s");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user