Skip to content

Commit 8b8e1db

Browse files
authored
Merge pull request #7 from AshherShahzad/master
get current time from server
2 parents 474d2bf + 77c3757 commit 8b8e1db

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Yii2TimerCountDown.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,19 @@ class Yii2TimerCountDown extends Widget
1818
* This option will accept count down date in millisecond, if you keep it empty the default value will be current time
1919
*/
2020
public $countDownDate;
21-
21+
22+
/*
23+
* @var bool
24+
* This option give you ability to set current Time from server.
25+
*/
26+
public $addServerTime = false;
27+
28+
/*
29+
* @var milisecond time
30+
* This option will accept start of count down in millisecond, if you keep it empty the default value will be current time
31+
*/
32+
public $now;
33+
2234
/*
2335
* @var string
2436
* This option give you apilty to change time Sperator, default sperator is : nested in tag.
@@ -36,7 +48,7 @@ class Yii2TimerCountDown extends Widget
3648

3749
/*
3850
* @var bool
39-
* This option give you apilty to set each number groub in tag contain general class called item-counter-down.
51+
* This option give you ability to set each number group in tag contain general class called item-counter-down.
4052
*/
4153
public $addSpanForResult = false;
4254

@@ -81,7 +93,10 @@ public function init(){
8193
parent::init();
8294

8395
if(empty($this->countDownDate)){
84-
$this->countDownDate = strtotime("now") * 1000;
96+
$this->countDownDate = time() * 1000;
97+
}
98+
if($this->addServerTime){
99+
$this->now = time() * 1000;
85100
}
86101

87102
// If you change default template or you need to use template, you most has an inner spans
@@ -107,6 +122,7 @@ public function registerClientScript()
107122
timeDownCounter({
108123
'countDownIdSelector': '$this->countDownIdSelector',
109124
'countDownDate': '$this->countDownDate',
125+
'now': '$this->now',
110126
'countDownResSperator': '$this->countDownResSperator',
111127
'countDownReturnData': '$this->countDownReturnData',
112128
'addSpanForResult': '$this->addSpanForResult',
@@ -120,7 +136,7 @@ public function registerClientScript()
120136

121137
$template1 = <<<temp1
122138
#$this->countDownIdSelector .item-counter-down {
123-
background: #c0c0c0;
139+
background: #000;
124140
display: inline-block;
125141
padding: 15px;
126142
font-size: 45px;

assets/js/Yii2TimerCountDown.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)