Skip to content

Commit

Permalink
Merge pull request #5 from bmwiedemann/date
Browse files Browse the repository at this point in the history
Allow to override build date with SOURCE_DATE_EPOCH
  • Loading branch information
AlephAlpha committed Jun 30, 2023
2 parents ac84210 + 853a860 commit b7cf03b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ let local_build_time = build_time_local!("%Y-%m-%dT%H:%M:%S%.f%:z");
```
*/

use chrono::{DateTime, Local, Utc};
use chrono::{DateTime, Local, TimeZone, Utc};
use once_cell::sync::Lazy;
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::quote;
use std::env;
use syn::{parse_macro_input, LitStr};

static BUILD_TIME: Lazy<DateTime<Utc>> = Lazy::new(Utc::now);
static BUILD_TIME: Lazy<DateTime<Utc>> = Lazy::new(|| match env::var("SOURCE_DATE_EPOCH") {
Ok(val) => { Utc.timestamp_opt(val.parse::<i64>().unwrap(), 0).unwrap() }
Err(_) => Utc::now(),
});

/// Build time in UTC.
///
Expand Down

0 comments on commit b7cf03b

Please sign in to comment.