@@ -288,7 +288,7 @@ impl Rule {
288288enum ConditionType {
289289 String ,
290290 Segment ,
291- Date ,
291+ Datetime ,
292292 Number ,
293293 SemVer ,
294294 #[ serde( other) ]
@@ -311,7 +311,7 @@ impl Condition {
311311 ConditionType :: Segment => self . match_segment ( user, & self . predicate , segment_repo) ,
312312 ConditionType :: Number => self . match_ordering :: < f64 > ( user, & self . predicate ) ,
313313 ConditionType :: SemVer => self . match_ordering :: < Version > ( user, & self . predicate ) ,
314- ConditionType :: Date => self . match_timestamp ( & self . predicate ) ,
314+ ConditionType :: Datetime => self . match_timestamp ( user , & self . predicate ) ,
315315 _ => false ,
316316 }
317317 }
@@ -383,8 +383,14 @@ impl Condition {
383383 false
384384 }
385385
386- fn match_timestamp ( & self , predicate : & str ) -> bool {
387- let c = unix_timestamp ( ) / 1000 ;
386+ fn match_timestamp ( & self , user : & FPUser , predicate : & str ) -> bool {
387+ let c: u128 = match user. get ( & self . subject ) {
388+ Some ( v) => match v. parse ( ) {
389+ Ok ( v) => v,
390+ Err ( _) => return false ,
391+ } ,
392+ None => unix_timestamp ( ) / 1000 ,
393+ } ;
388394 return match predicate {
389395 "after" => self . do_match :: < u128 > ( & c, |c, o| c. ge ( o) ) ,
390396 "before" => self . do_match :: < u128 > ( & c, |c, o| c. lt ( o) ) ,
@@ -1202,20 +1208,25 @@ mod condition_tests {
12021208 }
12031209
12041210 #[ test]
1205- fn test_date_condition ( ) {
1211+ fn test_datetime_condition ( ) {
12061212 let now_ts = unix_timestamp ( ) / 1000 ;
12071213 let mut condition = Condition {
1208- r#type : ConditionType :: Date ,
1209- subject : "" . to_owned ( ) ,
1214+ r#type : ConditionType :: Datetime ,
1215+ subject : "ts " . to_owned ( ) ,
12101216 objects : vec ! [ format!( "{}" , now_ts) ] ,
12111217 predicate : "after" . to_owned ( ) ,
12121218 } ;
12131219
12141220 let user = FPUser :: new ( "user" ) ;
12151221 assert ! ( condition. meet( & user, None ) ) ;
1222+ let user = FPUser :: new ( "user" ) . with ( "ts" . to_owned ( ) , format ! ( "{}" , now_ts) ) ;
1223+ assert ! ( condition. meet( & user, None ) ) ;
12161224
12171225 condition. predicate = "before" . to_owned ( ) ;
12181226 condition. objects = vec ! [ format!( "{}" , now_ts + 2 ) ] ;
1219- assert ! ( condition. meet( & user, None ) )
1227+ assert ! ( condition. meet( & user, None ) ) ;
1228+
1229+ let user = FPUser :: new ( "user" ) . with ( "ts" . to_owned ( ) , "a" . to_owned ( ) ) ;
1230+ assert ! ( !condition. meet( & user, None ) ) ;
12201231 }
12211232}
0 commit comments