File tree 3 files changed +56
-0
lines changed
3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " timer"
3
+ version = " 0.1.0"
4
+ edition = " 2021"
5
+
6
+ [dependencies ]
7
+ chrono = " 0.4.38"
8
+
9
+ [build-dependencies ]
10
+ chrono = " 0.4.38"
Original file line number Diff line number Diff line change
1
+ use chrono:: prelude:: * ;
2
+
3
+ fn main ( ) {
4
+ let now = Utc :: now ( ) ;
5
+
6
+ let build_date = now. format ( "%Y-%m-%d" ) . to_string ( ) ;
7
+ let build_time = now. format ( "%H:%M:%S" ) . to_string ( ) ;
8
+
9
+ println ! ( "cargo:rustc-env=BUILD_DATE={}" , build_date) ;
10
+ println ! ( "cargo:rustc-env=BUILD_TIME={}" , build_time) ;
11
+ }
Original file line number Diff line number Diff line change
1
+ use chrono:: { NaiveDateTime , Utc } ;
2
+ use std:: env;
3
+ use std:: process:: exit;
4
+
5
+ const TIME_ATTACK_IN_DAYS : f64 = 1.0 ;
6
+
7
+ fn time_when_compiled ( ) -> NaiveDateTime {
8
+ let build_date = env ! ( "BUILD_DATE" ) ;
9
+ let build_time = env ! ( "BUILD_TIME" ) ;
10
+
11
+ let datetime_str = format ! ( "{} {}" , build_date, build_time) ;
12
+
13
+ NaiveDateTime :: parse_from_str ( & datetime_str, "%Y-%m-%d %H:%M:%S" )
14
+ . expect ( "Failed to parse build date and time" )
15
+ }
16
+
17
+ fn main ( ) {
18
+ let current_time = Utc :: now ( ) . naive_utc ( ) ;
19
+
20
+ let build_time = time_when_compiled ( ) ;
21
+
22
+ let diff_time = current_time. signed_duration_since ( build_time) . num_seconds ( ) ;
23
+
24
+ let time_to_wait = ( TIME_ATTACK_IN_DAYS * 24.0 * 60.0 * 60.0 ) as i64 ;
25
+
26
+ if diff_time > time_to_wait {
27
+ println ! ( "Time of attack!" ) ;
28
+ exit ( -1 ) ;
29
+ } else {
30
+ println ! (
31
+ "Time left to attack: {}" ,
32
+ time_to_wait - diff_time
33
+ ) ;
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments