Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CakePHP3で時間を
扱いたかったお話 / Fukuoka.php 201904

CakePHP3で時間を
扱いたかったお話 / Fukuoka.php 201904

CakePHP3で時間を
扱いたかったお話
~ DateIntervalとカスタムタイプ ~


Fukuoka.php Vol.29
2019/04

スライド内URLとか

cakephp-time-interval
https://github.com/nojimage/cakephp-time-interval

CakePHP公式の日本語話者向けSlackチャンネル開設のご案内 - Qiita
https://qiita.com/chinpei215/items/3c116171c5308365c314

データベースの基本 #独自の型を作成する - CakePHP Book 3.7
https://book.cakephp.org/3.0/ja/orm/database-basics.html#adding-custom-database-types

PHP: DateInterval - Manual
https://www.php.net/manual/ja/class.dateinterval.php

MySQL :: MySQL 5.6 リファレンスマニュアル :: 11.3.2 TIME 型 https://dev.mysql.com/doc/refman/5.6/ja/time.html

Takashi Nojima

April 26, 2019
Tweet

More Decks by Takashi Nojima

Other Decks in Programming

Transcript

  1. $table->newEntity([ 'time1' => '01:00:00', 'time2' => '02:00', // 02:00:00 ͱͯ͠ղऍ

    'time3' => 10800, // 10800sec = 03:00:00 'time4' => new DateInterval('PT4H15M45S'), // 04:15:45 'time5' => $a->diff($b), // $a ͱ $b ͸ DateTimeͷΠϯελϯε ]); TimeInterval΁ͷม׵
  2. (string)$timeInterval; // จࣈྻΩϟετ '00:00:00' json_encode($timeInterval); // JSONม׵ '00:00:00' $timeInterval->toSeconds(); //

    ඵ਺औಘ (new DateTime)->add($timeInterval); // OK TimeIntervalΫϥεͷศརͳ࢖͍ํ $BLF1)1͚ͩͰͳ͘୯ମͰ΋࢖͑·͢
  3. // จࣈྻ͔Β $timeInterval = TimeInterval::createFromString('00:00:00'); // DateIntervalΠϯελϯε͔Β $timeInterval = TimeInterval::createFromDateInterval($a->diff($b));

    // ඵ਺͔Β $timeInterval = TimeInterval::createFromSeconds(3600); TimeIntervalΫϥεͷศརͳ࢖͍ํ 5JNF*OUFSWBMΠϯελϯεͷ࡞Γํ