shadow-rs icon indicating copy to clipboard operation
shadow-rs copied to clipboard

Timestamps in unix

Open Kathund opened this issue 3 weeks ago • 4 comments

Id love to get timestamps of stuff for example BUILD_TIME but non formatted and in unix timestamp form. This allows me to mess around with how it's displayed for the end user

Kathund avatar Dec 10 '25 07:12 Kathund

"Currently, shadow-rs provides several fields with pre-formatted timestamp strings, but it does not offer a pure numeric Unix timestamp field. If you wish to convert these formatted strings back to a numeric timestamp, you should consider doing a reverse conversion. This approach is not problematic.

For your reference, here are the existing formatted time fields provided by shadow-rs:

#[doc=r#"
The project build time, formatted in modified ISO 8601 format (`YYYY-MM-DD HH-MM ±hh-mm` where hh-mm is the offset from UTC)."#]
#[allow(dead_code)]
#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)]
pub const BUILD_TIME :&str = r#"2021-08-04 12:34:03 +00:00"#;

#[doc=r#"
The project build time, formatted according to [RFC 2822](https://datatracker.ietf.org/doc/html/rfc2822#section-3.3) (e.g. HTTP Headers)."#]
#[allow(dead_code)]
#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)]
pub const BUILD_TIME_2822 :&str = r#"Wed, 04 Aug 2021 12:34:03 +0000"#;

#[doc=r#"
The project build time, formatted according to [RFC 3339 and ISO 8601](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6)."#]
#[allow(dead_code)]
#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)]
pub const BUILD_TIME_3339 :&str = r#"2021-08-04T12:34:03Z"#;

You can use a date/time parsing library in Rust (like chrono) to parse one of these constants (e.g., BUILD_TIME_3339) and convert it into a numeric Unix timestamp (i64 or u64)."

baoyachi avatar Dec 10 '25 07:12 baoyachi

Yeah yeah! I'm aware as that's what i'm currently doing but I just thought it would be cool to have them resolve in unix as "it's a standard"

Kathund avatar Dec 11 '25 03:12 Kathund

I'm thinking of adding a BUILD_TIME_TIMESTAMP field or BUILD_TIME_UNIX field for you. Would that work? @Kathund

baoyachi avatar Dec 11 '25 05:12 baoyachi

I'm thinking of adding a BUILD_TIME_TIMESTAMP field or BUILD_TIME_UNIX field for you. Would that work? @Kathund

I mean probably. It would also be nice to have it for other timestamps not just BUILD_TIME

I think BUILD_TIME_UNIX makes the most sense

Kathund avatar Dec 11 '25 05:12 Kathund