pub fn time_since_game_ended(game_end_timestamp: u64) -> StringExpand description
⚙️ Function: Calculates the time elapsed since a game ended and returns it as a human-readable string.
This function computes the duration between the game’s end timestamp and the current time. It returns a string representing how much time has passed, formatted in seconds, minutes, hours, days, months, or years, depending on the duration.
§Parameters:
game_end_timestamp: A UNIX timestamp (in milliseconds) representing when the game ended.
§Returns:
String: A human-readable string representing how long ago the game ended (e.g., “5 minutes ago”, “2 hours ago”).
§⚠️ Notes:
- The function converts the timestamp from milliseconds to seconds before performing the calculation.
- If the duration is less than 60 seconds, the result will be in seconds. If it’s less than 24 hours, the result will be in minutes or hours, and so on.
§Example:
let time_elapsed = time_since_game_ended(1625000000000);
println!("{}", time_elapsed); // Output: "5 hours ago"The resulting string will vary depending on the duration since the game ended:
"2 minutes ago"
"5 days ago"
"1 year ago"