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

PHPで使える日時の表現と、その知り方 #frontend_phpcon_do

PHPで使える日時の表現と、その知り方 #frontend_phpcon_do

フロントエンド・PHPカンファレンス北海道2026での発表資料です(LT)
https://fortee.jp/frontend-phpcon-do-2026/proposal/77172968-2ab4-419b-a9eb-95080beabd75

Avatar for hideki kinjyo

hideki kinjyo PRO

June 06, 2026

More Decks by hideki kinjyo

Other Decks in Programming

Transcript

  1. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' ); 
  2. 自己紹介 • 金城秀樹 / きんじょうひでき • GitHub: @o0h / 𝕏

    : @o0h_ • アイコンは美味しい鮭親子丼の写真です • 東京でPHPを使っています • 最近はPodcastをやっています • ハッシュタグ: #readlinefm 
  3. datenocolon { s->time->y = timelib_get_nr(&ptr,4); s->time->m = timelib_get_nr(&ptr,2); s->time->d =

    timelib_get_nr(&ptr,2); }  「time」の「m」に 「次の数字2文字」を入れる
  4. datenocolon { s->time->y = timelib_get_nr(&ptr,4); s->time->m = timelib_get_nr(&ptr,2); s->time->d =

    timelib_get_nr(&ptr,2); }  「time」の「d」に 「次の数字2文字」を入れる
  5. monthfull | monthabbr { DEBUG_OUTPUT("monthtext"); TIMELIB_INIT; TIMELIB_HAVE_DATE(); s->time->m = timelib_lookup_month(&ptr);

    TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; }  s->time->m = timelib_lookup_month(&ptr); mouthfull
  6. datetextual | datenoyear { int length = 0; DEBUG_OUTPUT("datetextual |

    datenoyear"); TIMELIB_INIT; TIMELIB_HAVE_DATE(); s->time->m = timelib_get_month(&ptr); s->time->d = timelib_get_nr(&ptr, 2); s->time->y = timelib_get_nr_ex(&ptr, 4, &length); TIMELIB_PROCESS_YEAR(s->time->y, length); TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; } 
  7. datetextual | datenoyear { int length = 0; DEBUG_OUTPUT("datetextual |

    datenoyear"); TIMELIB_INIT; TIMELIB_HAVE_DATE(); s->time->m = timelib_get_month(&ptr); s->time->d = timelib_get_nr(&ptr, 2); s->time->y = timelib_get_nr_ex(&ptr, 4, &length); TIMELIB_PROCESS_YEAR(s->time->y, length); TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; }  datenoyear s->time->m = ... s->time->d = ...
  8. 'yesterday' { DEBUG_OUTPUT("yesterday"); TIMELIB_INIT; TIMELIB_HAVE_RELATIVE(); TIMELIB_UNHAVE_TIME(); s->time->relative.d = -1; TIMELIB_DEINIT;

    return TIMELIB_RELATIVE; }  ※ 画面上の都合で、内容を一部改修しています
  9. 'yesterday' { DEBUG_OUTPUT("yesterday"); TIMELIB_INIT; TIMELIB_HAVE_RELATIVE(); TIMELIB_UNHAVE_TIME(); s->time->relative.d = -1; TIMELIB_DEINIT;

    return TIMELIB_RELATIVE; }  s->time->relative.d = -1; 'yesterday' ※ 画面上の都合で、内容を一部改修しています
  10. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' ); 
  11. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  7月の第3月曜日
  12. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  10時の15分後 = 10:15:00
  13. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  s->time->relative.d += 3
  14. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  relativeに持っている値の +ーを反転
  15. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  s->time->relative.h += 99
  16. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  何もしない
  17. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  何もしない
  18. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  s->time->relative.i += 3
  19. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  s->time->y = 2021
  20. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  s->time->relative.d += (-1 * 7) s->time->relative.weekday = 1;
  21. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  s->time->z = 18.00 * 60 * 60
  22. <?php new \DateTimeImmutable( 'third mon of june back of 10

    -3days ago 99 hour now now 3min 2021 previous week +1800' );  2021-05-15 13:18:00.0 +18:00