Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

97
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ๆ”พ่ชฒๅพŒใ‚ขใƒˆใƒชใ‚จใจใ„ใ‚ ็ฌฌ65535่ฉฑใŒๅ…ฌ้–‹ใ•ใ‚ŒใŸ

Last updated at Posted at 2019-11-20

ๆ”พ่ชฒๅพŒใ‚ขใƒˆใƒชใ‚จใจใ„ใ‚

ๆ™‚ใฎ็‚บๆ”ฟ่€…ใซใ‚ˆใฃใฆๅฐๅฐใ•ใ‚Œใฆใ—ใพใฃใŸๅนปใฎๅไฝœใ€ๆ”พ่ชฒๅพŒใ‚ขใƒˆใƒชใ‚จใจใ„ใ‚็ฌฌ65535่ฉฑใŒ็‰นๅˆฅๅ…ฌ้–‹ใ•ใ‚Œใพใ—ใŸใ€‚
ใ•ใ‚ใ•ใฃใใ่ชญใ‚€ใ‚“ใ ใ€‚
ใใ—ใฆๆœฌๅฑ‹ใงๅ˜่กŒๆœฌใฎ1ๅทปใ‹ใ‚‰4ๅทปใพใงใ‚’่ฒทใ„ๅ ใ‚ใฆ็ทจ้›†้ƒจใซๅ†้–‹ใฎใƒ—ใƒฌใƒƒใ‚ทใƒฃใƒผใ‚’ๆŽ›ใ‘ใ‚‹ใ‚“ใ ใ€‚

ใ‚ใ€่จ€ใ„ใŸใ„ใ“ใจใฏใ‚‚ใ†็ต‚ใ‚ใฃใŸใฎใงๅธฐใฃใฆใ„ใ„ใงใ™ใ‚ˆใ€‚

ใงใ‚‚ใ“ใ“ใง็ต‚ใ‚ใ‚‹ใจไธๆ€่ญฐใชใ“ใจใซไฝ•ๆ•…ใ‹ๆถˆใ•ใ‚Œใฆใ—ใพใ†ใฎใงใ€ใ“ใ“ใ‹ใ‚‰ไธ‹ใซใฏใชใ‚“ใ‹้ฉๅฝ“ใซใŠใพใ‘ใงใ‚‚็ฝฎใ„ใจใใพใ™ใ€‚

Bug #78827 Wrong timestamp

ใ•ใฆๅ•้กŒใงใ™ใ€‚
ไปฅไธ‹ใฎๅ‡บๅŠ›ใฏใฉใ†ใชใ‚‹ใงใ—ใ‚‡ใ†ใ€‚

$today = strtotime('last Wednesday');

var_dump(
    (strtotime('last Wednesday') - $today) / 86400,
    (strtotime('last Wednesday + 1 day') - $today) / 86400,
    (strtotime('last Wednesday + 2 day') - $today) / 86400,
    (strtotime('last Wednesday + 3 day') - $today) / 86400,
    (strtotime('last Wednesday + 4 day') - $today) / 86400,
    (strtotime('last Wednesday + 5 day') - $today) / 86400,
    (strtotime('last Wednesday + 6 day') - $today) / 86400,
    (strtotime('last Wednesday + 7 day') - $today) / 86400,
    (strtotime('last Wednesday + 8 day') - $today) / 86400,
    (strtotime('last Wednesday + 9 day') - $today) / 86400,
);

Expected result

ใพใš$todayใฏ"ๅ…ˆ้€ฑใฎๆฐดๆ›œๆ—ฅใ€0ๆ™‚0ๅˆ†0็ง’"ใซใชใ‚Šใพใ™ใ€‚
ๅฎŸ่กŒใ—ใŸใฎใŒๆœจๆ›œใงใ‚ใ‚Œใฐๆ˜จๆ—ฅใ€้‡‘ๆ›œใงใ‚ใ‚Œใฐไธ€ๆ˜จๆ—ฅใ€ใใ—ใฆไปŠๆ—ฅใŒๆฐดๆ›œใงใ‚ใ‚Œใฐ7ๆ—ฅๅ‰ใซใชใ‚Šใพใ™ใ€‚

ใงใฏvar_dumpใฎ่กŒใ‚’่ฆ‹ใฆใ„ใใพใ—ใ‚‡ใ†ใ€‚

ใพใšlast Wednesdayใฎ่กŒใงใ™ใŒใ€ใ“ใ“ใฏๅŒใ˜ๅ€คใ‚’ๅผ•ใ„ใฆใ‚‹ใ ใ‘ใชใฎใงๅฝ“็„ถ0ใซใชใ‚Šใพใ™ใ€‚

ๆฌกใซlast Wednesday + 1 dayใงใ™ใŒใ€ใ“ใ“ใฏ"ๅ…ˆ้€ฑใฎๆฐดๆ›œๆ—ฅใ‹ใ‚‰+1ๆ—ฅใ€0ๆ™‚0ๅˆ†0็ง’"ใจใชใ‚Šใพใ™ใ€‚
ๅฎŸ่กŒใ—ใŸใฎใŒๆœจๆ›œใงใ‚ใ‚ŒใฐไปŠๆ—ฅใ€้‡‘ๆ›œใงใ‚ใ‚Œใฐๆ˜จๆ—ฅใฎใ“ใจใงใ€ใใ—ใฆไปŠๆ—ฅใŒๆฐดๆ›œใงใ‚ใ‚Œใฐ6ๆ—ฅๅ‰ใซใชใ‚Šใพใ™ใ€‚
ๅ˜ใซ1ๆ—ฅใšใ‚‰ใ—ใŸใ ใ‘ใชใฎใงใ€ๅฝ“็„ถใชใŒใ‚‰$todayใจใฎใšใ‚Œใฏๅฟ…ใš1ๆ—ฅใงใ™ใ€‚
ใจใ„ใ†ใ“ใจใง(strtotime('last Wednesday + 1 day') - $today) / 86400ใฎ็ญ”ใˆใฏใ€ไฝ•ๆ›œๆ—ฅใซๅฎŸ่กŒใ—ใŸใจใ—ใฆใ‚‚ๅฟ…ใš1ใงใ™ใ€‚

ๅŒใ˜ใlast Wednesday + 2 dayใฎ็ญ”ใˆใฏๅฟ…ใš2ใ€last Wednesday + 3 dayใฎ็ญ”ใˆใฏๅฟ…ใš3ใ€ใจใชใ‚Šใพใ™ใ€‚
ใใ‚“ใชใ‹ใ‚“ใ˜ใง็ถšใ„ใฆใ„ใฃใฆใ€ไธ€็•ชไธ‹ใฎlast Wednesday + 9 dayใฎ็ญ”ใˆใฏๅฟ…ใš9ใงใ™ใ€‚
20191120-01.png
ๅฝ“็„ถใงใ™ใญใ€‚

Actual result

ๆฐดๆ›œๆ—ฅใซๅฎŸ่กŒใ™ใ‚‹ใจใ“ใ†ใชใ‚Šใพใ™ใ€‚
20191120-02.png
ใชใ‚“ใงใ ใ‚ˆใ€‚

ใƒปๆฐดๆ›œๆ—ฅไปฅๅค–ใซstrtotime('last Wednesday + 6 day')ใ‚’่จˆ็ฎ—ใ™ใ‚‹ใจใ€6ๆ—ฅๅพŒใฎๅ€คใซใชใ‚‹ใ€‚
ใƒปๆฐดๆ›œๆ—ฅไปฅๅค–ใซstrtotime('last Wednesday + 7 day')ใ‚’่จˆ็ฎ—ใ™ใ‚‹ใจใ€7ๆ—ฅๅพŒใฎๅ€คใซใชใ‚‹ใ€‚
ใƒปๆฐดๆ›œๆ—ฅใซstrtotime('last Wednesday + 6 day')ใ‚’่จˆ็ฎ—ใ™ใ‚‹ใจใ€6ๆ—ฅๅพŒใฎๅ€คใซใชใ‚‹ใ€‚
ใƒปๆฐดๆ›œๆ—ฅใซstrtotime('last Wednesday + 7 day')ใ‚’่จˆ็ฎ—ใ™ใ‚‹ใจใ€14ๆ—ฅๅพŒใฎๅ€คใซใชใ‚‹ใ€‚

ๆ›ธๅผใฎๆ›œๆ—ฅใŒๅฎŸ่กŒใ—ใŸๆ›œๆ—ฅใจๅŒใ˜ๅ ดๅˆใฎใฟใ€7ๆ—ฅไปฅไธŠใฎๆ—ฅใ‚’่ถณใ™ใจไฝ•ๆ•…ใ‹ๅ€คใŒใšใ‚Œใ‚‹ใจใ„ใ†ใƒใ‚ฐใงใ™ใ€‚

ใ‚ใพใ‚Šไฝฟใ‚ใชใ„ใ‚ˆใ†ใชๆ›ธใๆ–นใ‚’ใ—ใŸใ†ใˆใงใ€ใ•ใ‚‰ใซ็‰นๅฎšใฎๆ›œๆ—ฅใซใ—ใ‹็™บ็”Ÿใ—ใชใ„ใจใ„ใ†ใ“ใจใงใ€ไธ‡ไธ€ใ“ใ‚Œใ‚’่ธใ‚“ใงใ—ใพใฃใŸใ‚‰ๅŽŸๅ› ใฎ็‰นๅฎšใŒ้žๅธธใซๅ›ฐ้›ฃใซใชใ‚Šใใ†ใชใƒใ‚ฐใงใ™ใญใ€‚

ใ‚ใพใ‚Šไฝฟใ‚ใชใ„ใจใ„ใ†ใฎใฏใคใพใ‚Šใ€ๆ™ฎ้€šใฏlast Wednesday + 7 dayใ˜ใ‚ƒใชใใฆnext Wednesdayใฃใฆๆ›ธใใงใ—ใ‚‡ใ†ใจใ„ใ†ใ“ใจใงใ™ใŒใ€‚

next Wednesday

ใ“ใฎใƒใ‚ฐใƒใ‚ฑใซใฏ่ผ‰ใฃใฆใชใ„ใฎใงใ™ใŒใ€ๅฎŸใฏnextใงใ‚‚ๅŒใ˜ใƒใ‚ฐใŒ่ตทใ“ใ‚Šใพใ™ใ€‚

$today = strtotime('next Wednesday');

var_dump(
    (strtotime('next Wednesday') - $today) / 86400,
    (strtotime('next Wednesday - 1 day') - $today) / 86400,
    (strtotime('next Wednesday - 2 day') - $today) / 86400,
    (strtotime('next Wednesday - 3 day') - $today) / 86400,
    (strtotime('next Wednesday - 4 day') - $today) / 86400,
    (strtotime('next Wednesday - 5 day') - $today) / 86400,
    (strtotime('next Wednesday - 6 day') - $today) / 86400,
    (strtotime('next Wednesday - 7 day') - $today) / 86400,
    (strtotime('next Wednesday - 8 day') - $today) / 86400,
    (strtotime('next Wednesday - 9 day') - $today) / 86400,
);

ๆฐดๆ›œๆ—ฅไปฅๅค–ใซๅฎŸ่กŒใ™ใ‚‹ใจ[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]ใงใ™ใŒใ€ๆฐดๆ›œๆ—ฅใซๅฎŸ่กŒใ™ใ‚‹ใจ[0, -8, -9, -10, -11, -12, -13, -14, -15, -16]ใซใชใ‚Šใพใ™ใ€‚
ใ“ใกใ‚‰ใฏ-1ใง่ตทใ“ใ‚‹ใฎใงใ€ใ‚ˆใ‚Šๆทฑๅˆปใงใ™ใญใ€‚

Bug #78496 date_create rolls a day back on year 0000 timestamp

ๅ•้กŒใงใ™ใ€‚
ไปฅไธ‹ใฎๅ‡บๅŠ›ใฏใฉใ†ใชใ‚‹ใงใ—ใ‚‡ใ†ใ€‚

$timestamp = strtotime('0000-02-20 00:00:00 UTC');
echo gmdate('Y-m-d H:i:s', $timestamp);
echo date_create('@' . $timestamp)->format('Y-m-d H:i:s');

Expected result

ๅฝ“็„ถใงใ™ใŒใ€ใฉใกใ‚‰ใ‚‚"0000-02-20 00:00:00"ใซใชใ‚Šใพใ™ใ‚ˆใญใ€‚

Actual result

20191120-03.png

ใชใ‚“ใงใ ใ‚ˆใ€‚

0ๅนดใซใคใ„ใฆใฏdate_createใŒๆญฃใ—ใ่จˆ็ฎ—ใ•ใ‚Œใชใ„ใจใ„ใ†ใƒใ‚ฐใŒใ‚ใ‚Šใพใ™ใ€‚
่ฅฟๆšฆ0ๅนดใฏๅญ˜ๅœจใ—ใชใ„ใจใ‹ใ„ใ†ใƒ„ใƒƒใ‚ณใƒŸใŒ่žใ“ใˆใฆใใใ†ใงใ™ใŒใ€ISO 8601ใงใฏ"0000"ๅนดใฏ็ด€ๅ…ƒๅ‰1ๅนดใ€"-0001"ๅนดใฏ็ด€ๅ…ƒๅ‰2ๅนดใ‚’่กจใ—ใพใ™ใ€‚
ใ‚ใฃใกใ‚ƒใ‚ใ‹ใ‚Šใซใใ„ใ€‚

date_create

date_create้–ขๆ•ฐใฎใƒ˜ใƒซใƒ—ใซใฏใ€ŽDateTime::__construct() ใฎใ‚จใ‚คใƒชใ‚ขใ‚นใ€ใจๆ›ธใ‹ใ‚Œใฆใ„ใ‚‹ใฎใงใ™ใŒใ€ใ“ใ‚Œๅ˜˜ใงใ™ใ€‚

var_dump(date_create('2020/01/32')); // false
var_dump(new DateTime('2020/01/32')); // Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string

ๆ›ธๅผใŒ็†่งฃใงใใชใ„ๅ ดๅˆใ€date_createใฏfalseใ‚’่ฟ”ใ—ใพใ™ใŒDateTime::__construct()ใฏไพ‹ๅค–ใ‚’่ตทใ“ใ—ใพใ™ใ€‚

Bug #78452 diff makes wrong in hour for Asia/Tehran

ใ•ใฆๅ•้กŒใงใ™ใ€‚
ไปฅไธ‹ใฎๅ‡บๅŠ›ใฏใฉใ†ใชใ‚‹ใงใ—ใ‚‡ใ†ใ€‚

date_default_timezone_set('Asia/Tokyo');
$date1 = new \DateTime('2019-11-05 11:00:00');
$date2 = new \DateTime('2019-11-01 12:00:00');
echo $date1->diff($date2)->format('%H');

date_default_timezone_set('America/New_York');
$date1 = new \DateTime('2019-11-05 11:00:00');
$date2 = new \DateTime('2019-11-01 12:00:00');
echo $date1->diff($date2)->format('%H');

Expected result

ไปŠๅ›žๅ‡บๅŠ›ใ—ใฆใ„ใ‚‹ใฎใฏๆ™‚้–“ใฎๅทฎๅˆ†ใชใฎใงใ€ๆœˆใŒ้•ใ†ใ“ใจใฏๅฝฑ้Ÿฟใ—ใพใ›ใ‚“ใ€‚
ๆฑไบฌใฏๅฝ“็„ถใงใ™ใŒใใฎใพใพ23ใงใ™ใญใ€‚
ใƒ‹ใƒฅใƒผใƒจใƒผใ‚ฏใฏๅคๆ™‚้–“ๅˆ‡ใ‚Šๆ›ฟใˆใ‚’ๆŒŸใ‚€ใฎใงใฉใ†ใ„ใ†่จˆ็ฎ—ใซใชใ‚‹ใฎใ‹ใ‚ˆใใ‚ใ‹ใ‚‰ใชใ„ใฎใงใ™ใŒใ€ๆ™‚้–“ๅทฎใ‚’ๆฑ‚ใ‚ใ‚‹ๅ ดๅˆใฏ23ใงใ„ใ„ใฎใงใ™ใ‹ใญ๏ผŸ

Actual result

78452.png
ใชใ‚“ใงใ ใ‚ˆใ€‚

ๅคๆ™‚้–“ใฎๅˆ‡ใ‚Šๆ›ฟใˆใ‚’ใพใŸใใจไฝ•ๆ•…ใ‹ใƒžใ‚คใƒŠใ‚นใซใชใ‚‹ใ“ใจใŒใ‚ใ‚Šใพใ™ใ€‚
ๆญฃ่งฃใŒใฉใฎๅ€คใ‹ใฏใ‚ใ‹ใ‚Šใพใ›ใ‚“ใŒใ€ๅฐ‘ใชใใจใ‚‚-1ใฏๆ˜Žใ‚‰ใ‹ใซ้–“้•ใ„ใงใ™ใญใ€‚

ๅคๆ™‚้–“ใ‚’่€ƒใˆใฆใชใ„ๅ‹˜้•ใ„ใƒใ‚ฐๅ ฑๅ‘Šใฏใ‚ใ‚Šใจใ‚ˆใใ‚ใ‚‹ใฎใงใ™ใŒใ€ใ“ใฎใƒใ‚ฑใƒƒใƒˆใซใคใ„ใฆใฏ้–“้•ใ„ใชใใƒใ‚ฐใงใ™ใ€‚

Bug #78504 Add warnings to DateTime object with incompatible timezone info

ใ•ใฆๅ•้กŒใงใ™ใ€‚
ไปฅไธ‹ใฎๅ‡บๅŠ›ใฏใฉใ†ใชใ‚‹ใงใ—ใ‚‡ใ†ใ€‚

$tz = new DateTimeZone('Asia/Tokyo');
$ts = strtotime('2020-01-1 00:00:00');

$dt1 = DateTime::CreateFromFormat("YmdHis", date('YmdHis', $ts), $tz);
$dt2 = DateTime::CreateFromFormat("U", date('U', $ts), $tz);

var_dump(
    $dt1->format("Y-m-d H:i:s"),
    $dt2->format("Y-m-d H:i:s"),
);

Expected result

ๅฝ“็„ถใ€ไธกๆ–นใจใ‚‚2020-01-01 00:00:00ใงใ™ใญใ€‚

Actual result

ๅ‰่€…ใฏ2020-01-01 00:00:00ใ€ๅพŒ่€…ใฏ2019-12-31 15:00:00ใงใ™ใ€‚
ใชใ‚“ใงใ ใ‚ˆใ€‚

ๅฎŸใฏใƒ‘ใƒฉใƒกใƒผใ‚ฟใ‚’ใ‚ฟใ‚คใƒ ใ‚นใ‚ฟใƒณใƒ—ใงๆธกใ—ใŸๅ ดๅˆใ€ๅผ•ๆ•ฐใฎใ‚ฟใ‚คใƒ ใ‚พใƒผใƒณใฏ็„ก่ฆ–ใ•ใ‚ŒใฆUTCๆ‰ฑใ„ใ•ใ‚Œใพใ™ใ€‚

ใ“ใ‚Œใฏใƒžใƒ‹ใƒฅใ‚ขใƒซใซๆ›ธใ‹ใ‚Œใฆใ„ใ‚‹ใฎใงใ™ใŒใ€ใ‚ใพใ‚Šใซใ‚ใ‹ใ‚Šใซใใ„ใงใ™ใญใ€‚
ๅพ“ใฃใฆใ€ใ“ใฎๆŒ™ๅ‹•ใฏPHP8ใ‹9ใ‚ใŸใ‚Šใงๅค‰ๆ›ดใซใชใ‚‹ๅฏ่ƒฝๆ€งใŒใ‚ใ‚Šใพใ™ใ€‚

and

ใ•ใฆๅ•้กŒใงใ™ใ€‚
ไปฅไธ‹ใฎๅ‡บๅŠ›ใฏใฉใ†ใชใ‚‹ใงใ—ใ‚‡ใ†ใ€‚

$diff = DateInterval::createFromDateString('1 year and 2 months');

Expected result

1ๅนด2ใƒถๆœˆๅทฎใฎDateIntervalใ‚ชใƒ–ใ‚ธใ‚งใ‚ฏใƒˆใ€‚

Actual result

PHP7.2.17ไปฅ้™ใ€ใใ—ใฆ7.3.4ไปฅ้™ใ‚จใƒฉใƒผใซใชใ‚Šใพใ™ใ€‚

ChangeLogใซใฏๅ…จใๆ›ธใ‹ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚
ใŠใใ‚‰ใ50020ใฎใƒใ‚ฐไฟฎๆญฃใจไธ€็ท’ใซๅ…ฅใ‚Š่พผใ‚“ใ ใ‚‚ใฎใงใฏใชใ„ใ‹ใจๆ€ใ„ใพใ™ใŒ็ขบ่จผใฏใ‚ใ‚Šใพใ›ใ‚“ใ€‚

ไฝ•ใŒๅ•้กŒใ‹ใฃใฆๅ˜ใซ'and'ใจใ„ใ†ๆ–‡ๅญ—ๅˆ—ใซๅฏพๅฟœใ—ใฆใชใ„ใจใ„ใ†ใ“ใจใชใฎใงใ€'1 year 2 months'ใซใ™ใ‚Œใฐๅ•้กŒใชใๅ‹•ไฝœใ—ใพใ™ใ€‚
ๅ…ƒใ€…ๅฏพๅฟœใ—ใฆใชใ‹ใฃใŸใฎใซใŸใพใŸใพๅ‹•ใ„ใฆใ„ใŸใจใ„ใ†ใ‚„ใคใชใฎใงใ€ไฝฟใ†ๆ–นใŒๆ‚ชใ„ใจใ„ใˆใฐใใ†ใชใฎใงใ™ใŒใ€ใงใ‚‚ใ‚ตใ‚คใƒฌใƒณใƒˆใซๆŒ™ๅ‹•ใŒๅค‰ใ‚ใ‚‹ใจใณใใฃใจใชใ‚Šใพใ™ใญใ€‚

ใพใจใ‚

ๅ…ฌ้–‹ใ•ใ‚ŒใŸใจใ‹่จ€ใฃใฆใŸใ‘ใฉใ€็ถšใใŒ่ชญใฟใŸใใฆใฉใ†ใ—ใ‚ˆใ†ใ‚‚ใชใใฆๆˆ‘ๆ…ขใงใใชใ‹ใฃใŸใ‹ใ‚‰ๆใ„ใฆใ‚‚ใ‚‰ใฃใŸใ‚“ใงใ™ใ‘ใฉใญใ€‚
ใ•ใ‚ใฟใ‚“ใชใ‚‚ใฉใ‚“ใฉใ‚“ไพ้ ผใ™ใ‚‹ใฎใ ใ€‚

97
43
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

@rana_kualu's pickup articles

rana_kualu

@rana_kualu

ไธๅŠดๆ‰€ๅพ—ใง็”ŸใใŸใ„ใ€‚

Today's trending articles

2026ๅนด!ๅˆใ‚ขใ‚ฆใƒˆใƒ—ใƒƒใƒˆใ‚’ใ—ใ‚ˆใ†
oageST

ไบบ็”Ÿๅˆใฎๅ‰ฏๆฅญใงใ€่ฆไปถๅฎš็พฉใƒปใ‚นใ‚ฑใ‚ธใƒฅใƒผใƒซ็ฎก็†ใƒปAPI็”ณ่ซ‹ใƒปๆœฌๆฅญใƒใƒƒใƒ†ใ‚ฃใƒณใ‚ฐใซๅ…จ้ƒจใ‚„ใ‚‰ใ‚ŒใŸ่ฉฑ

Linked from these articles

Comments

This comment has been deleted for violation of our Terms of Service.
This comment has been deleted for violation of our Terms of Service.
This comment has been deleted for violation of our Terms of Service.
This comment has been deleted for violation of our Terms of Service.

Let's comment your feelings that are more than good

Being held Article posting campaign

97
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Login to continue?

Login or Sign up with social account

Login or Sign up with your email address