Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit 4157ec4

Browse files
committed
fixed timer to pass all test cases
1 parent 5ecd765 commit 4157ec4

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

src/Asm/Config/ConfigTimer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function setConfig($file)
8989
foreach ($timers as $timerSubKey => $params) {
9090

9191
foreach ($params as $paramKey => $paramValue) {
92-
$config[$timerKey][$timerSubKey][$paramKey] = array(
92+
$config[$timerKey][$timerSubKey] = array(
9393
new \DateTime($paramValue),
9494
new \DateTime($paramValue . ' 23:59:59'),
9595
);

src/Asm/Test/TestData.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,20 @@ public static function getYamlTimerConfigFile()
7575
holiday:
7676
use_gerneral: true # if false, uses separate holidays conf
7777
additional: [ sub, 1 ] # add or subract n days to holiday to create range
78-
interval:
79-
- [ "16:00:00", "16:00:00" ] # start and end time
78+
79+
example_timer_config_7:
80+
holiday:
81+
use_gerneral: true # if false, uses separate holidays conf
82+
additional: [ sub, 1 ] # add or subract n days to holiday to create range
83+
interval:
84+
- [ "16:00:00", "16:00:00" ] # start and end time
8085
8186
general_shipping_promise:
8287
holiday:
8388
use_general: true
8489
additional: [ sub, 1 ] # add or subract n days to holiday to create range
85-
interval:
86-
- [ "16:00:00", "16:00:00" ] # start and end time
90+
interval:
91+
- [ "16:00:00", "16:00:00" ] # start and end time
8792
day: [ monday, tuesday, wednesday, thursday, friday, sunday ]
8893
8994
shipping_promise_sunday:

src/Asm/Tests/Timer/TimerTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function testConstruct()
5050
* @covers \Asm\Timer\Timer::checkDays
5151
* @covers \Asm\Timer\Timer::checkTime
5252
* @covers \Asm\Timer\Timer::checkHoliday
53+
* @covers \Asm\Timer\Timer::flush
5354
* @param Timer $timer
5455
*/
5556
public function testIsTimerActive(Timer $timer)
@@ -59,8 +60,9 @@ public function testIsTimerActive(Timer $timer)
5960
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_3')));
6061
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_4')));
6162
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_5')));
62-
//$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_6')));
63-
//$this->assertTrue(is_bool($timer->isTimerActive('general_shipping_promise')));
63+
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_6')));
64+
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_7')));
65+
$this->assertTrue(is_bool($timer->isTimerActive('general_shipping_promise')));
6466
}
6567

6668
/**
@@ -71,8 +73,8 @@ public function testIsTimerActive(Timer $timer)
7173
*/
7274
public function testIsHoliday(Timer $timer)
7375
{
74-
$this->assertFalse($timer->isHoliday('2014-03-03 00:00:00'));
75-
$this->assertTrue($timer->isHoliday('2014-12-24 12:30:01'));
76-
$this->assertTrue(is_bool($timer->isHoliday()));
76+
$this->assertFalse($timer->isHoliday('2014-03-03 00:00:00'), 'failed to check non-holiday date');
77+
$this->assertTrue($timer->isHoliday('2014-12-24 12:30:01'), 'failed to validate christmas');
78+
$this->assertTrue(is_bool($timer->isHoliday()), 'failed to validate bool return');
7779
}
7880
}

src/Asm/Timer/Timer.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function isTimerActive($type)
8080
$return = $this->checkDate();
8181
}
8282

83+
$this->flush();
8384
return $return;
8485
}
8586

@@ -105,6 +106,15 @@ public function getHoliday()
105106
return $this->holiday;
106107
}
107108

109+
/**
110+
* clear current configuration
111+
*/
112+
public function flush()
113+
{
114+
$this->currentConf = array();
115+
$this->holiday = null;
116+
}
117+
108118
/**
109119
* date checks on config
110120
*
@@ -223,11 +233,6 @@ private function checkIntervals(array $intervals = array())
223233
}
224234

225235
foreach ($intervals as $interval) {
226-
// this means: just some time
227-
if (!is_a($interval[0], 'DateTime') || !is_a($interval[1], 'DateTime')) {
228-
$interval = $this->checkTime($intervals);
229-
}
230-
231236
$intervalStart = $today->diff($interval[0]);
232237
$intervalEnd = $today->diff($interval[1]);
233238

0 commit comments

Comments
 (0)