@@ -21,20 +21,22 @@ export class ProblemsComponent implements OnInit {
2121 contestname ;
2222 time ;
2323
24- // Called after the constructor, initializing input properties, and the first call to ngOnChanges.
25- //Add 'implements OnInit' to the class.
24+ // Called after the constructor, initializing input properties, and the first call to ngOnChanges.
25+ // Add 'implements OnInit' to the class.
2626 countDownDate ;
2727 now ;
2828 end ;
2929 distance ;
30- days = 0 ;
30+ days = 0 ;
3131 hours ;
3232 minutes ;
3333 seconds ;
3434 times ;
3535 start ;
3636 x ;
37- ticks = 0 ;
37+ ticks = 0 ;
38+ typeOfNow = 'Contest Will Start In' ;
39+ conditionToShowProblem = false ;
3840 constructor (
3941 private contestService : ContestService ,
4042 private router : Router ,
@@ -51,26 +53,33 @@ export class ProblemsComponent implements OnInit {
5153 this . start = new Date ( contest . msg [ 0 ] . startTime ) ;
5254 this . end = new Date ( contest . msg [ 0 ] . endTime ) ;
5355 var timer ;
54- if ( this . start > new Date ( ) )
55- var compareDate = this . start ;
56- else
57- var compareDate = this . end ;
58- //compareDate.setDate(this.end.getDate()); //just for this demo today + 7 days
5956
60- //console.log(compareDate);
57+ if ( this . start > new Date ( ) ) {
58+ var compareDate = this . start ;
59+ } else if ( this . start <= new Date ( ) && this . end >= new Date ( ) ) {
60+ this . typeOfNow = 'Contest Will End In' ;
61+ var compareDate = this . end ;
62+ this . conditionToShowProblem = true ;
63+ } else {
64+ this . typeOfNow = 'Contest Ended' ;
65+ this . conditionToShowProblem = true ;
66+ }
67+ // compareDate.setDate(this.end.getDate()); //just for this demo today + 7 days
68+
69+ // console.log(compareDate);
6170 /* timer = setInterval(function() {
6271 timeBetweenDates(compareDate);
6372 }, 1000);*/
64- setInterval ( ( ( ) => {
65- var dateEntered = compareDate ;
73+ setInterval ( ( ( ) => {
74+ var dateEntered = compareDate ;
6675 var now = new Date ( ) ;
6776 var difference = dateEntered . getTime ( ) - now . getTime ( ) ;
6877
6978 if ( difference <= 0 ) {
7079
7180 // Timer done
7281 clearInterval ( timer ) ;
73-
82+ this . times = '' ;
7483 } else {
7584
7685 var second = Math . floor ( difference / 1000 ) ;
@@ -81,7 +90,7 @@ export class ProblemsComponent implements OnInit {
8190 hour %= 24 ;
8291 minute %= 60 ;
8392 second %= 60 ;
84- //console.log(day,hour,minute,second);
93+ // console.log(day,hour,minute,second);
8594 // this.days = day;
8695 // this.hours = hour;
8796 // this.minutes = minute;
@@ -93,18 +102,17 @@ export class ProblemsComponent implements OnInit {
93102 var temp = String(day) + ' days ' + String(hour) + ' hr ' +String(minute) + ' min ' +String(second) + ' sec';
94103 ////this.contestService.time.next(temp);
95104 //this.contestService.time.subscribe(value => this.times = value);*/
96- this . times = String ( day ) + ' days ' + String ( hour ) + ' hr ' + String ( minute ) + ' min ' + String ( second ) + ' sec' ;
105+ this . times = String ( day ) + ' days ' + String ( hour ) + ' hr ' + String ( minute ) + ' min ' + String ( second ) + ' sec' ;
97106
98107 }
99- } ) , 1000 ) ;
100-
108+ } ) , 1000 ) ;
101109
102110 } ) ;
103111 this . contestService . currentContest . subscribe ( contest => this . contestname = contest ) ;
104112
105113
106114 }
107- tickerFunc ( tick ) {
115+ tickerFunc ( tick ) {
108116 this . ticks = tick ;
109117 }
110118 onAddProblem ( ) {
0 commit comments