Show duration in turns

O01eg
Oct 13, 2022, 6:31 AM
A2LJT7TTVA6XDEQ6N27T7KKFGBH6AMF6KQI6J7AOVUZDLIN6HCMAC

Dependencies

  • [2] GUAEZDLE Add turns info to slow game's page
  • [3] G3VK7RIB Add FreeOrion forum's URL to slow game's
  • [4] C6F7SJZI Add players count to slow game's page
  • [5] 6NYILMKI Add page for slow game

Change contents

  • edit in src/pages/slow_game.rs at line 18
    [2.246]
    [3.870]
    }
    fn naive_to_diff_utc(
    naive: chrono::NaiveDateTime,
    now: chrono::DateTime<chrono::Utc>,
    ) -> (chrono::DateTime<chrono::Utc>, chrono::Duration) {
    let ts = chrono::DateTime::<chrono::Utc>::from_utc(naive, chrono::Utc);
    (ts, now - ts)
    }
    fn diff_utc_to_string((ts, diff): (chrono::DateTime<chrono::Utc>, chrono::Duration)) -> String {
    let (part, part_diff) = if diff.num_weeks() != 0 {
    ("weeks", diff.num_weeks())
    } else if diff.num_days() != 0 {
    ("days", diff.num_days())
    } else if diff.num_hours() != 0 {
    ("hours", diff.num_hours())
    } else if diff.num_minutes() != 0 {
    ("minutes", diff.num_minutes())
    } else {
    ("seconds", diff.num_seconds())
    };
    format!(
    "{} ({} {})",
    ts.format("%Y %b %d %H:%M UTC"),
    part_diff,
    part
    )
  • edit in src/pages/slow_game.rs at line 89
    [3.2401]
    [3.2401]
    let now = chrono::Utc::now();
    let min_turn_ts = row
    .get::<_, Option<chrono::NaiveDateTime>>(4)
    .map(|x| naive_to_diff_utc(x, now));
    let max_turn_ts = row
    .get::<_, Option<chrono::NaiveDateTime>>(5)
    .map(|x| naive_to_diff_utc(x, now));
  • replacement in src/pages/slow_game.rs at line 107
    [3.90][2.247:845]()
    min_turn_ts: row.get::<_, Option<chrono::NaiveDateTime>>(4).map(|x| {
    format!(
    "{}",
    chrono::DateTime::<chrono::Utc>::from_utc(x, chrono::Utc)
    .format("%Y %b %d %H:%M UTC")
    )
    }),
    max_turn_ts: row.get::<_, Option<chrono::NaiveDateTime>>(5).map(|x| {
    format!(
    "{}",
    chrono::DateTime::<chrono::Utc>::from_utc(x, chrono::Utc)
    .format("%Y %b %d %H:%M UTC")
    )
    }),
    [3.90]
    [2.845]
    min_turn_ts: min_turn_ts.map(diff_utc_to_string),
    max_turn_ts: max_turn_ts.map(diff_utc_to_string),