ts_to_date

Function ts_to_date 

Source
pub fn ts_to_date(ts: Option<i64>) -> String
Expand description

What: Convert an optional Unix timestamp (seconds) to a UTC date-time string.

Inputs:

  • ts: Optional Unix timestamp in seconds since epoch.

Output:

  • Returns a formatted string YYYY-MM-DD HH:MM:SS (UTC), or empty string for None, or numeric string for negative timestamps.

Details:

  • Returns an empty string for None.
  • Negative timestamps are returned as their numeric string representation.
  • Output format: YYYY-MM-DD HH:MM:SS (UTC).
  • This implementation performs a simple conversion using loops and does not account for leap seconds.

ยงExamples

use pacsea::util::ts_to_date;

// Converting the timestamp for the release of a significant Arch Linux package update
// Example: A major 'glibc' or 'linux' package release
assert_eq!(ts_to_date(Some(1680307200)), "2023-04-01 00:00:00");

// Converting the 'LastModified' timestamp from an AUR package's metadata
// This is commonly used to show when a package was last updated in the AUR
assert_eq!(ts_to_date(Some(1704067200)), "2024-01-01 00:00:00");

// Handling the case where no timestamp is available (e.g., a package with no build date)
assert_eq!(ts_to_date(None), "");