43 $origDateValueNull = empty($dateValue);
46 $method = self::validateMethod($method);
47 if ($dateValue === null) {
48 $dateValue = (SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_MAC_1904 || $method ===
Constants::DOW_SUNDAY) ? 0 : 1;
50 $dateValue = self::validateDateValue($dateValue);
51 if (!$dateValue && self::buggyWeekNum1900($method)) {
56 return $e->getMessage();
60 $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
64 return (
int) $PHPDateObject->format(
'W');
66 if (self::buggyWeekNum1904($method, $origDateValueNull, $PHPDateObject)) {
70 $dayOfYear = (int) $PHPDateObject->format(
'z');
71 $PHPDateObject->modify(
'-' . $dayOfYear .
' days');
72 $firstDayOfFirstWeek = (int) $PHPDateObject->format(
'w');
73 $daysInFirstWeek = (6 - $firstDayOfFirstWeek + $method) % 7;
74 $daysInFirstWeek += 7 * !$daysInFirstWeek;
75 $endFirstWeek = $daysInFirstWeek - 1;
76 $weekOfYear = floor(($dayOfYear - $endFirstWeek + 13) / 7);
78 return (
int) $weekOfYear;
96 if (self::apparentBug($dateValue)) {
103 return $e->getMessage();
107 $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
110 return (
int) $PHPDateObject->format(
'W');
137 return $e->getMessage();
141 $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
143 $DoW = (int) $PHPDateObject->format(
'w');
151 $DoW = self::dow0Becomes7($DoW);
155 $DoW = self::dow0Becomes7($DoW) - 1;
170 if (!is_numeric(
$style)) {
183 return ($DoW === 0) ? 7 : $DoW;
192 if (SharedDateHelper::getExcelCalendar() !== SharedDateHelper::CALENDAR_MAC_1904) {
193 if (is_bool($dateValue)) {
196 if (is_numeric($dateValue) && !((
int) $dateValue)) {
211 if (is_bool($dateValue)) {
225 if ($method === null) {
229 if (!is_numeric($method)) {
233 $method = (int) $method;
244 return $method ===
Constants::DOW_SUNDAY && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900;
251 return $method ===
Constants::DOW_SUNDAY && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_MAC_1904 &&
252 !$origNull && $dateObject->format(
'Y-m-d') ===
'1904-01-01';
static apparentBug($dateValue)
static validateDateValue($dateValue)
Validate dateValue parameter.
static buggyWeekNum1904(int $method, bool $origNull, DateTime $dateObject)
static number($dateValue, $method=Constants::STARTWEEK_SUNDAY)
WEEKNUM.
static validateStyle($style)
static dow0Becomes7(int $DoW)
const STARTWEEK_MONDAY_ISO
static day($dateValue, $style=1)
WEEKDAY.
static isoWeekNumber($dateValue)
ISOWEEKNUM.
static getDateValue($dateValue, bool $allowBool=true)
getDateValue.
static silly1900(DateTime $PHPDateObject, string $mod='-1 day')
static validateMethod($method)
Validate method parameter.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static buggyWeekNum1900(int $method)