@@ -16,10 +16,14 @@ pub struct VersionInfo {
1616 releaselevel : & ' static str ,
1717 serial : usize ,
1818}
19+ extern crate chrono;
20+ use chrono:: prelude:: DateTime ;
21+ use chrono:: Local ;
22+ use std:: time:: { Duration , UNIX_EPOCH } ;
1923
2024pub fn get_version ( ) -> String {
2125 format ! (
22- "{} {:?} { }" ,
26+ "{:.80} ({:.80}) {:.80 }" ,
2327 get_version_number( ) ,
2428 get_build_info( ) ,
2529 get_compiler( )
@@ -42,16 +46,28 @@ pub fn get_version_number() -> String {
4246
4347pub fn get_compiler ( ) -> String {
4448 let rustc_version = rustc_version_runtime:: version_meta ( ) ;
45- format ! ( "rustc {}" , rustc_version. semver)
49+ format ! ( "\n [ rustc {}] " , rustc_version. semver)
4650}
4751
48- pub fn get_build_info ( ) -> ( String , String ) {
49- let git_hash = get_git_revision ( ) ;
52+ pub fn get_build_info ( ) -> String {
5053 // See: https://reproducible-builds.org/docs/timestamps/
51- let git_timestamp = option_env ! ( "RUSTPYTHON_GIT_TIMESTAMP" )
52- . unwrap_or ( "" )
53- . to_string ( ) ;
54- ( git_hash, git_timestamp)
54+ let git_revision = get_git_revision ( ) ;
55+ let separator = if git_revision. is_empty ( ) { "" } else { ":" } ;
56+
57+ let git_identifier = get_git_identifier ( ) ;
58+
59+ format ! (
60+ "{id}{sep}{revision}, {date:.20}, {time:.9}" ,
61+ id = if git_identifier. is_empty( ) {
62+ "default" . to_string( )
63+ } else {
64+ git_identifier
65+ } ,
66+ sep = separator,
67+ revision = git_revision,
68+ date = get_git_date( ) ,
69+ time = get_git_time( ) ,
70+ )
5571}
5672
5773pub fn get_git_revision ( ) -> String {
@@ -78,3 +94,34 @@ pub fn get_git_identifier() -> String {
7894 git_tag
7995 }
8096}
97+
98+ fn get_git_timestamp_datetime ( ) -> DateTime < Local > {
99+ let timestamp = option_env ! ( "RUSTPYTHON_GIT_TIMESTAMP" )
100+ . unwrap_or ( "" )
101+ . to_string ( ) ;
102+ let timestamp = timestamp. parse :: < u64 > ( ) . unwrap_or ( 0 ) ;
103+
104+ let datetime = UNIX_EPOCH + Duration :: from_secs ( timestamp) ;
105+ let datetime = DateTime :: < Local > :: from ( datetime) ;
106+
107+ datetime
108+ }
109+
110+ pub fn get_git_date ( ) -> String {
111+ let datetime = get_git_timestamp_datetime ( ) ;
112+
113+ datetime. format ( "%b %e %Y" ) . to_string ( )
114+ }
115+
116+ pub fn get_git_time ( ) -> String {
117+ let datetime = get_git_timestamp_datetime ( ) ;
118+
119+ datetime. format ( "%H:%M:%S" ) . to_string ( )
120+ }
121+
122+ pub fn get_git_datetime ( ) -> String {
123+ let date = get_git_date ( ) ;
124+ let time = get_git_time ( ) ;
125+
126+ format ! ( "{} {}" , date, time)
127+ }
0 commit comments