Skip to content
Snippets Groups Projects
Commit 561d91de authored by Jelle van der Waa's avatar Jelle van der Waa
Browse files

Add rust example for SOURCE_DATE_EPOCH

parent 7f620930
No related branches found
No related tags found
1 merge request!81Add rust example for SOURCE_DATE_EPOCH
Pipeline #432718 passed with stage
in 2 minutes and 52 seconds
......@@ -380,6 +380,24 @@ sys.env.get("SOURCE_DATE_EPOCH")
.map(sde => new java.util.Date(sde.toLong * 1000))
```
### Rust
Using the `chrono` crate:
```rust
use chrono::{DateTime, NaiveDateTime, Utc};
use std::env;
let now = match env::var("SOURCE_DATE_EPOCH") {
Ok(val) => {
let naive = NaiveDateTime::from_timestamp(val.parse::<i64>().unwrap(), 0);
let datetime: DateTime<Utc> = DateTime::from_utc(naive, Utc);
datetime
}
Err(_) => Utc::now(),
};
```
### Last-resort using faketime
''As a last resort to be avoided where possible'' (e.g. if the upstream tool is too hard to patch, or too time-consuming for you right now to patch, or if they are being uncooperative or unresponsive), package maintainers may try something like the following:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment