[Git][reproducible-builds/reproducible-website][master] Add rust example for SOURCE_DATE_EPOCH
Holger Levsen (@holger)
gitlab at salsa.debian.org
Thu Sep 29 16:43:31 UTC 2022
Holger Levsen pushed to branch master at Reproducible Builds / reproducible-website
Commits:
ea2f4306 by Jelle van der Waa at 2022-09-29T18:43:16+02:00
Add rust example for SOURCE_DATE_EPOCH
Signed-off-by: Holger Levsen <holger at layer-acht.org>
- - - - -
1 changed file:
- _docs/source-date-epoch.md
Changes:
=====================================
_docs/source-date-epoch.md
=====================================
@@ -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:
View it on GitLab: https://salsa.debian.org/reproducible-builds/reproducible-website/-/commit/ea2f4306aa8099168b283edcf97fe48b528864dd
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/reproducible-website/-/commit/ea2f4306aa8099168b283edcf97fe48b528864dd
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20220929/c83107d2/attachment.htm>
More information about the rb-commits
mailing list