Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8497144053 | ||
|
|
2006798388 | ||
|
|
bf63d850ca |
@@ -458,6 +458,47 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dateRangeHasWeekendProvider(): array
|
||||
{
|
||||
return [
|
||||
'no weekend' => [
|
||||
'2023-07-03',
|
||||
'2023-07-04',
|
||||
false
|
||||
],
|
||||
'start weekend sat' => [
|
||||
'2023-07-01',
|
||||
'2023-07-04',
|
||||
true
|
||||
],
|
||||
'start weekend sun' => [
|
||||
'2023-07-02',
|
||||
'2023-07-04',
|
||||
true
|
||||
],
|
||||
'end weekend sat' => [
|
||||
'2023-07-03',
|
||||
'2023-07-08',
|
||||
true
|
||||
],
|
||||
'end weekend sun' => [
|
||||
'2023-07-03',
|
||||
'2023-07-09',
|
||||
true
|
||||
],
|
||||
'long period > 6 days' => [
|
||||
'2023-07-03',
|
||||
'2023-07-27',
|
||||
true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* date string convert test
|
||||
*
|
||||
@@ -780,6 +821,29 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::dateRangeHasWeekend
|
||||
* @dataProvider dateRangeHasWeekendProvider
|
||||
* @testdox dateRangeHasWeekend $start_date and $end_date are expected weekend $expected [$_dataName]
|
||||
*
|
||||
* @param string $start_date
|
||||
* @param string $end_date
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testDateRangeHasWeekend(
|
||||
string $start_date,
|
||||
string $end_date,
|
||||
bool $expected
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::dateRangeHasWeekend($start_date, $end_date)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -143,6 +143,26 @@ print "DATE-dow[$date];invalid: " . DateTime::setWeekdayNameFromDate($date) . "<
|
||||
print "DATE-dow[$date],long;invalid: " . DateTime::setWeekdayNameFromDate($date, true) . "<br>";
|
||||
print "DOW-date[$date];invalid: " . DateTime::setWeekdayNumberFromDate($date) . "<br>";
|
||||
|
||||
// check date range includes a weekend
|
||||
// does not:
|
||||
$start_date = '2023-07-03';
|
||||
$end_date = '2023-07-05';
|
||||
print "Has Weekend: " . $start_date . " ~ " . $end_date . ": "
|
||||
. Dgs::prBl(DateTime::dateRangeHasWeekend($start_date, $end_date)) . "<br>";
|
||||
$start_date = '2023-07-03';
|
||||
$end_date = '2023-07-10';
|
||||
print "Has Weekend: " . $start_date . " ~ " . $end_date . ": "
|
||||
. Dgs::prBl(DateTime::dateRangeHasWeekend($start_date, $end_date)) . "<br>";
|
||||
$start_date = '2023-07-03';
|
||||
$end_date = '2023-07-31';
|
||||
print "Has Weekend: " . $start_date . " ~ " . $end_date . ": "
|
||||
. Dgs::prBl(DateTime::dateRangeHasWeekend($start_date, $end_date)) . "<br>";
|
||||
$start_date = '2023-07-01';
|
||||
$end_date = '2023-07-03';
|
||||
print "Has Weekend: " . $start_date . " ~ " . $end_date . ": "
|
||||
. Dgs::prBl(DateTime::dateRangeHasWeekend($start_date, $end_date)) . "<br>";
|
||||
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -222,7 +222,17 @@ if ($is_secure) {
|
||||
}
|
||||
// define the db config set name, the db config and the db schema
|
||||
define('DB_CONFIG_NAME', $SITE_CONFIG[HOST_NAME]['db_host'] ?? '');
|
||||
define('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME] ?? []);
|
||||
define('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME] ?? [
|
||||
'db_name' => '',
|
||||
'db_user' => '',
|
||||
'db_pass' => '',
|
||||
'db_host' => '',
|
||||
'db_port' => 5432,
|
||||
'db_schema' => '',
|
||||
'db_encoding' => '',
|
||||
'db_type' => '',
|
||||
'db_ssl' => ''
|
||||
]);
|
||||
// because we can't change constant, but we want to for db debug flag
|
||||
$GLOBALS['DB_CONFIG_SET'] = DB_CONFIG;
|
||||
// define('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']);
|
||||
|
||||
@@ -87,7 +87,7 @@ $l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
$locale['encoding']
|
||||
$locale['encoding'],
|
||||
);
|
||||
|
||||
// create smarty object
|
||||
|
||||
@@ -164,6 +164,10 @@ class Backend
|
||||
);
|
||||
}
|
||||
$this->default_acl = $set_default_acl_level ?? DEFAULT_ACL_LEVEL;
|
||||
// if negative or larger than 100, reset to 0
|
||||
if ($this->default_acl < 0 || $this->default_acl > 100) {
|
||||
$this->default_acl = 0;
|
||||
}
|
||||
|
||||
// queue key
|
||||
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action)) {
|
||||
|
||||
@@ -452,6 +452,31 @@ class DateTime
|
||||
return $days;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a weekend day (sat/sun) is in the given date range
|
||||
* Can have time too, but is not needed
|
||||
*
|
||||
* @param string $start_date Y-m-d
|
||||
* @param string $end_date Y-m-d
|
||||
* @return bool True for has weekend, False for has not
|
||||
*/
|
||||
public static function dateRangeHasWeekend(
|
||||
string $start_date,
|
||||
string $end_date,
|
||||
): bool {
|
||||
$dd_start = new \DateTime($start_date);
|
||||
$dd_end = new \DateTime($end_date);
|
||||
if (
|
||||
// starts with a weekend
|
||||
$dd_start->format('N') >= 6 ||
|
||||
// start day plus diff will be 6 and so fall into a weekend
|
||||
((int)$dd_start->format('w') + $dd_start->diff($dd_end)->days) >= 6
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -814,13 +814,13 @@ class IO
|
||||
switch ($id) {
|
||||
case 'DB_ERROR':
|
||||
$this->log->error(
|
||||
$debug_id . ' :' . $prefix . $error_string,
|
||||
$prefix . $error_string,
|
||||
$context
|
||||
);
|
||||
break;
|
||||
case 'DB_WARNING':
|
||||
$this->log->warning(
|
||||
$debug_id . ' :' . $prefix . $error_string,
|
||||
$prefix . $error_string,
|
||||
$context
|
||||
);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user