Pro Yearly is on sale from $80 to $50! »

A Tale about Time - PHPDay 2018

A Tale about Time - PHPDay 2018

Timezones, DST, human readable diffs, standardised formats, intervals, getting the last Tuesday of next month… Dealing with timestamps seems easy, but there’s a lot to it. It’s very easy to do it wrong. Learn how to do this properly and you’ll never be chasing weird time related bugs anymore!

39eb3f3d313b13f05534e496285040b8?s=128

Hannes Van De Vreken

May 12, 2018
Tweet

Transcript

  1. A Tale about Time @hannesvdvreken @phpday

  2. Hi, my name is Hannes.

  3. This is a 50 minute talk in 25 minutes.

  4. “We'd like to start the happy hour 30 minutes earlier

    than previously planned … and the best solution would be to move your talk”
  5. None
  6. None
  7. None
  8. None
  9. EDT = UTC-04:00 CEST = UTC+02:00

  10. None
  11. None
  12. EDT = UTC-04:00 CEST = UTC+02:00

  13. # UTC+05:30

  14. UTC+05:45 $

  15. DST CET/CEST

  16. Helsinki Sunrise: 9:24 - 3:54 Sunset: 15:13 - 22:50 Quito

    Sunrise: 6:08 - 6:12 Sunset: 18:16 - 18:19
  17. None
  18. None
  19. EST/EDT - March 12 CET/CEST - March 24

  20. %

  21. &/'

  22. Calendars

  23. Weeks - 7 days Starts on Monday. Or Sunday? First

    week of the year?
  24. Months Lunar vs Tropical

  25. Years Lunisolar vs Tropical

  26. 2018AD 1500BC

  27. Leap years

  28. Leap years Leap seconds

  29. Storing vs Expressing time

  30. Expressing time: 6:00PM vs 18:00

  31. Expressing time: May 12 12/05/2018

  32. Storing time: 1521261900

  33. Storing time: 1521261900 >1970-01-01T00:00:00+00:00

  34. Storing time: 1521261900 >1970-01-01T00:00:00+00:00 <2038-01-19T03:14:07+00:00 (32bit)

  35. Storing time: RFC3339: 2018-03-17T10:15:00+05:30

  36. Storing time: RFC3339 extended: 2018-03-17T10:15:00.000+05:30

  37. Storing time: Sortable (in UTC): 2018-03-17T05:45:00.000+00:00

  38. Storing time: Sortable (in UTC): 2018-03-17T05:45:00.000+00:00 + user’s location for

    timezone & locale
  39. Time in PHP

  40. DateTimeInterface - DateTime (date, time, tz) - DateTimeImmutable

  41. $date = DateTimeImmutable::createFromMutable($mutable);

  42. Change in PHP 7.1: microseconds

  43. $date = $date->setTimezone('Europe/Rome');

  44. // Magic $date = new DateTimeImmutable('now'); $date = $date->modify('first day

    of next month');
  45. “now + 5 hours” “first day of next month” "first

    weekday” …
  46. “2016-03-00” → “2016-02-29” “2018-06-31” → “2018-07-01” …

  47. “69-12-31” → “2069-12-31” “70-01-01” → “1970-01-01” …

  48. nesbot/carbon - Mutable cakephp/chronos - Immutable

  49. interface Clock { public function now(): DateTimeImmutable }

  50. The future

  51. E=mc²

  52. c ~ 299.000.000m/s

  53. None
  54. None
  55. None
  56. (new DateTimeImmutable(‘now’)) ->setPlanet(new Planet(‘mars’));

  57. Wrapping up

  58. Thanks for your time! @hannesvdvreken @phpday

  59. Time for questions. @hannesvdvreken @phpday