Skip to content

Commit

Permalink
Longhorn PHP date/time talk, now with Quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Apr 20, 2018
1 parent 1876272 commit d21dcfe
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 58 deletions.
4 changes: 2 additions & 2 deletions slides/time/basic-parse-time-new.xml
Expand Up @@ -4,7 +4,7 @@

<blurb>Parsing strings for date time information:</blurb>
<example><![CDATA[<?php
$dt = new DateTime("2010-03-08 08:43:57");
$dt = new DateTime("2018-03-08 08:43:57");
?>]]></example>
<break/>

Expand All @@ -14,7 +14,7 @@
<break/>

<example result="1"><![CDATA[<?php
$dt = new DateTime("2010-03-08 08:44:12");
$dt = new DateTime("2018-03-08 08:44:12");
echo $dt->format( 'U' ), "\n";
?>]]></example>
<break/>
Expand Down
2 changes: 1 addition & 1 deletion slides/time/date-modify-immutable1.xml
Expand Up @@ -4,7 +4,7 @@

<blurb>Standard:</blurb>
<example result="1"><![CDATA[<?php
$ts = new DateTime("2014-03-08 15:53:55");
$ts = new DateTime("2018-04-17 15:53:55");
$new = $ts->modify("+2 days");
echo $ts->format(DateTime::RFC2822), "\n";
echo $new->format(DateTime::RFC2822), "\n";
Expand Down
2 changes: 1 addition & 1 deletion slides/time/date-modify-immutable2.xml
Expand Up @@ -4,7 +4,7 @@

<blurb>Immutable (new in PHP 5.5):</blurb>
<example result="1"><![CDATA[<?php
$ts = new DateTimeImmutable("2014-03-08 15:53:55");
$ts = new DateTimeImmutable("2018-04-17 15:53:55");
$new = $ts->modify("+2 days");
echo $ts->format(DateTime::RFC2822), "\n";
echo $new->format(DateTime::RFC2822), "\n";
Expand Down
8 changes: 4 additions & 4 deletions slides/time/date-modify.xml
Expand Up @@ -4,7 +4,7 @@

<example result="0"><![CDATA[<?php
date_default_timezone_set("Europe/London");
$ts = new DateTime("2010-03-08 15:53:55");
$ts = new DateTime("2018-03-17 15:53:55");
$ts->modify("+2 days");
Expand All @@ -16,8 +16,8 @@
<blurb>Result:</blurb>
<blurb class='pre'> Mon, 08 Mar 2010 15:53:55 +0000</blurb>

<blurb effect="fade-in" class='pre'> |ef2929|Wed, 10 Mar| 2010 15:53:55 +0000</blurb>
<blurb effect="fade-in" class='pre'> |ef2929|Fri, 02 Apr| 2010 15:53:55 |ef2929|+0100|</blurb>
<blurb effect="fade-in" class='pre'> Fri, |ef2929|09 Apr| 2010 15:53:55 +0100</blurb>
<blurb effect="fade-in" class='pre'> |ef2929|Mon, 19 Mar| 2018 15:53:55 +0000</blurb>
<blurb effect="fade-in" class='pre'> |ef2929|Fri, 13 Apr| 2018 00:00:00 |ef2929|+0100|</blurb>
<blurb effect="fade-in" class='pre'> Fri, |ef2929|20 Apr| 2018 00:00:00 +0100</blurb>

</slide>
4 changes: 2 additions & 2 deletions slides/time/date-parse2.xml
Expand Up @@ -2,11 +2,11 @@
<slide>
<title>Parsing Dates</title>

<blurb align='center'>"|a4000000|22||3464a4|apr||f57900|2006| |ad7fa8|8|:|ef2929|36|:|73d216|14| # |c4a000|Europe/Oslo| |75507b|CEST|"</blurb>
<blurb align='center'>"|a4000000|22||3464a4|apr||f57900|2018| |ad7fa8|8|:|ef2929|36|:|73d216|14| # |c4a000|Europe/Oslo| |75507b|CEST|"</blurb>

<blurb>Parsing strings with the ~date_parse()~ function:</blurb>
<example result="1"><![CDATA[<?php
$date = "22apr2006 8:36:14.43 # Europe/Oslo CEST";
$date = "22apr2018 8:36:14.43 # Europe/Oslo CEST";
$t = date_parse( $date );
echo $t['year'], '-', $t['month'], '-', $t['day'], " ";
Expand Down
30 changes: 15 additions & 15 deletions slides/time/default-timezone.xml
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<slide>
<title>Default Timezones</title>
<title>Default Timezones</title>

<blurb>Setting a default timezone:</blurb>
<example result="0"><![CDATA[<?php
date_default_timezone_set("Europe/Oslo");
$ts = new DateTime("1978-12-22 09:15");
echo $ts->format("e");
<blurb>Setting a default timezone:</blurb>
<example result="0"><![CDATA[<?php
date_default_timezone_set("Europe/Oslo");
$ts = new DateTime("1978-12-22 09:15");
echo $ts->format("e");
?>]]></example>
<break/>

<blurb>Getting a default timezone:</blurb>
<example result="0"><![CDATA[<?php
$default_identifier = date_default_timezone_get();
echo $default_identifier;
<blurb>Getting a default timezone:</blurb>
<example result="0"><![CDATA[<?php
$default_identifier = date_default_timezone_get();
echo $default_identifier;
?>]]></example>
<break/>

<blurb>Default timezone is 'guessed' in the following order:</blurb>
<list>
<bullet>~date_default_timezone_set()~ value</bullet>
<bullet>php.ini's %date.timezone% setting</bullet>
</list>
<blurb>Default timezone is 'guessed' in the following order:</blurb>
<list>
<bullet>~date_default_timezone_set()~ value</bullet>
<bullet>php.ini's %date.timezone% setting</bullet>
</list>
</slide>
28 changes: 14 additions & 14 deletions slides/time/in-database4.xml
@@ -1,26 +1,26 @@
<slide>
<title>Storing date/time in a database</title>
<subtitle>Conclusion</subtitle>

<blurb>If you want to future proof a specific date and time (Oct 1st,
13:00)-ie, storing a time in *local time*:</blurb>
<example><![CDATA[{
'title' : 'Giving a talk: Advanced Date/Time handling with PHP',
'time' : {
'tz': 'America/Montreal',
'dt': '2012-10-01 13:00',
}
}]]></example>
<break />
<subtitle>Summary</subtitle>

<blurb>If you want to store a time for an appointment for a group of people
all in different timezones-ie, store a *specific point in time*:</blurb>
<example><![CDATA[{
'title' : 'Meeting about getting rid of Daylight Saving Time',
'time' : {
'tz': 'America/Montreal',
'ts': 1349110800,
'ts': ISODate("2018-04-19 15:27:32"),
'tz': 'Europe/London',
},
'attendees' : [ 'Arthur David Olson', 'Paul Eggert' ],
}]]></example>
<break />

<blurb>If you want to future proof a specific date and time (Oct 1st,
13:00)-ie, storing a time in *local time*:</blurb>
<example><![CDATA[{
'title' : 'Giving a talk: Advanced Date/Time handling with PHP',
'time' : {
'dt': '2018-04-18 19:40',
'tz': 'Europe/London',
}
}]]></example>
</slide>
31 changes: 31 additions & 0 deletions slides/time/in-mdb1.xml
@@ -0,0 +1,31 @@
<slide>
<title>Storing date/time in a database</title>
<subtitle>Query in MongoDB</subtitle>

<example><![CDATA[{
'title' : 'Giving a talk: Advanced Date/Time handling with PHP',
'time' : {
'ts': ISODate("2018-04-19 15:27:32"), // ms since Epoch
'tz': 'Europe/London',
}
}]]></example>

<blurb>Query:</blurb>
<example><![CDATA[
db.dates.aggregate( { '$project' : {
local_date: {
'$dateToString' : {
format: '%Y-%m-%d %H:%M:%S',
date: '$time.ts',
timezone: '$time.tz'
}
}
} } );
]]></example>

<blurb>Result:</blurb>
<example><![CDATA[{
"_id" : ObjectId("5ad8a9148cb588e5ea33f228"),
"local_date" : "2018-04-19 16:34:57"
}]]></example>
</slide>
8 changes: 4 additions & 4 deletions slides/time/intervals-2.xml
Expand Up @@ -4,7 +4,7 @@
<blurb>Applying an interval</blurb>

<example result="0"><![CDATA[<?php
$d = new DateTimeImmutable( 'Aug 28th, 2009' );
$d = new DateTimeImmutable( 'Apr 20th, 2018' );
echo $d->format( "l Y-m-d\n" );
$i = DateInterval::createFromDateString( "next weekday" );
Expand All @@ -15,8 +15,8 @@ echo $d->sub( $i )->format( "l Y-m-d\n" );
?>]]></example>

<blurb>Result:</blurb>
<blurb class='pre'> Friday 2009-08-28</blurb>
<blurb effect="fade-in" class='pre'> Monday 2009-08-31</blurb>
<blurb effect="fade-in" class='pre'> Thursday 2009-05-18</blurb>
<blurb class='pre'> Friday 2018-04-20</blurb>
<blurb effect="fade-in" class='pre'> Monday 2018-04-23</blurb>
<blurb effect="fade-in" class='pre'> Wednesday 2018-01-10</blurb>

</slide>
2 changes: 1 addition & 1 deletion slides/time/intervals.xml
Expand Up @@ -12,7 +12,7 @@ $i = new DateInterval( 'P3DT6H' );
// from a difference
$d1 = new DateTimeImmutable();
$d2 = new DateTimeImmutable( "2014-06-20 11:45 Europe/London" );
$d2 = new DateTimeImmutable( "2018-04-21 11:00 Europe/London" );
$i = $d1->diff( $d2 );
// displaying the difference
Expand Down
6 changes: 3 additions & 3 deletions slides/time/period-2.xml
Expand Up @@ -4,10 +4,10 @@
<subtitle>Iterating over a period</subtitle>

<example result="1"><![CDATA[<?php
$db = new DateTimeImmutable( '2013-12-31' );
$de = new DateTimeImmutable( '2014-12-31' );
$db = new DateTimeImmutable( '2017-12-31' );
$de = new DateTimeImmutable( '2018-12-31' );
$di = DateInterval::createFromDateString(
'third tuesday of next month'
'first thursday of next month'
);
$dp = new DatePeriod(
$db, $di, $de, DatePeriod::EXCLUDE_START_DATE
Expand Down
Binary file added slides/time/queries.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions slides/time/quiz.xml
@@ -0,0 +1,30 @@
<slide>
<title>Quiz Time!</title>

<break lines="4"/>

<div effect="fade-in-out"><blurb class="big-centre">each day has *24&#160;hours*</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">each day is *23,&#160;24&#160;or&#160;25 hours*</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">every time exists *only once* during a day</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">Februari has *29&#160;or&#160;30* days</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">every year is *365* days</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">every year is *365&#160;or&#160;366* days</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">everybody understands what *PI&#160;day* is</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">everybody understands what *4/20 means*</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">timezones are *whole&#160;hour* offsets from UTC</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">timezones are *half&#160;hour* offsets from UTC</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">jump *to DST* is around March</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">the difference between standard and DST is *an hour*</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">DST is always *ahead* of standard time</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">each country has *one* timezone</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">China spans *5&#160;geographical* timezones</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">DST rules stay always the *same*</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">DST rules are announced *at&#160;least&#160;a&#160;year* in advance</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">DST rules are announced *in&#160;advance*</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">PST is *Pacific&#160;Standard&#160;Time*</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">a timezone identifier is the capital of a region</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">date calculations are easy</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">"2018-03-31" plus month is "2018-04-31"</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">"2018-03-31" plus month is "2018-04-30"</blurb></div>
<div effect="fade-in-out"><blurb class="big-centre">every date calculation is reversable</blurb></div>
</slide>
8 changes: 4 additions & 4 deletions slides/time/relative-month.xml
Expand Up @@ -4,18 +4,18 @@
<subtitle>"previous month" / "next month"</subtitle>

<example result="1"><![CDATA[<?php
$date = new DateTimeImmutable( '2014-01-31 15:48:21' );
$date = new DateTimeImmutable( '2018-01-31 15:48:21' );
echo $date->modify( 'next month' )->format( 'Y-m-d' ), "\n";
?>]]></example>
<break/>

<div effect="hide">
<blurb>Explanation:</blurb>
<blurb effect="fade-out" class='pre'> 2014-01-31 15:48:21</blurb>
<blurb effect="fade-in-out" class='pre'> 2014-|ef2929|02|-31 15:48:21
<blurb effect="fade-out" class='pre'> 2018-01-31 15:48:21</blurb>
<blurb effect="fade-in-out" class='pre'> 2018-|ef2929|02|-31 15:48:21

"next month" increases month number by 1</blurb>
<blurb effect="fade-in" class='pre'> 2014-|ef2929|03-03| 15:48:21
<blurb effect="fade-in" class='pre'> 2018-|ef2929|03-03| 15:48:21

February only has 28 days, so days are overflown
into the next month</blurb>
Expand Down
8 changes: 4 additions & 4 deletions slides/time/relative-month3.xml
Expand Up @@ -4,18 +4,18 @@
<subtitle>"first day *of* next month"</subtitle>

<example result="1"><![CDATA[<?php
$date = new DateTimeImmutable( '2014-01-31 15:48:21' );
$date = new DateTimeImmutable( '2018-01-31 15:48:21' );
echo $date->modify( 'first day of next month' )->format( 'Y-m-d' ), "\n";
?>]]></example>
<break/>

<div effect="hide">
<blurb>Explanation:</blurb>
<blurb effect="fade-out" class='pre'> 2014-01-31 15:48:21</blurb>
<blurb effect="fade-in-out" class='pre'> 2014-|ef2929|02|-31 15:48:21
<blurb effect="fade-out" class='pre'> 2018-01-31 15:48:21</blurb>
<blurb effect="fade-in-out" class='pre'> 2018-|ef2929|02|-31 15:48:21

"next month" increases month number by 1</blurb>
<blurb effect="fade-in" class='pre'> 2014-02-|ef2929|01| 15:48:21
<blurb effect="fade-in" class='pre'> 2018-02-|ef2929|01| 15:48:21

"first day of" resets the day number to 1</blurb>
</div>
Expand Down
6 changes: 3 additions & 3 deletions slides/time/timestamps-suck.xml
Expand Up @@ -3,17 +3,17 @@
<title>Unix timestamps and timezones</title>

<example result="1"><![CDATA[<?php
$date = strtotime( '2014-03-07 20:48:21 America/Toronto' );
$date = strtotime( '2018-03-07 20:48:21 America/Toronto' );
echo date( 'Y-m-d', $date ), "\n";
?>]]></example>

<div effect="hide">
<blurb>Explanation:</blurb>
<blurb >%$d = strtotime('2014-03-07 20:48 America/Toronto');%</blurb>
<blurb >%$d = strtotime('2018-03-07 20:48 America/Toronto');%</blurb>
<blurb effect="fade-in">%$d = |ef2929|1394243280|; // string is turned into a number%</blurb>
<blurb effect="fade-in">%echo date('Y-m-d', 1394243280), "\n";%</blurb>
<blurb effect="fade-in">Number is converted to a date/time string using the *default* timezone:<br/>
%"2014-03-08" |555753|(01:48:21 Europe/London)|%</blurb>
%"2018-03-08" |555753|(01:48:21 Europe/London)|%</blurb>
</div>

</slide>
63 changes: 63 additions & 0 deletions time-longhorn18.xml
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<presentation css="10gen-strict.css">
<topic>Localization and Internationalization</topic>
<title>Time Zones and Calendars are a PITA</title>
<event>Longhorn PHP</event>
<location>Austain, TX, US</location>
<date>April 21st, 2018</date>
<speaker>Derick Rethans</speaker>
<email>derick@php.net</email>
<url>http://derickrethans.nl/talks.html</url>
<joindin>http://joind.in/23637</joindin>
<twitter>derickr</twitter>

<slide>slides/mongodb/title.xml</slide>
<slide>slides/mongodb/me.xml</slide>

<!-- INTRODUCTION -->
<slide>slides/time/quiz.xml</slide>
<slide>slides/time/problems-condensed.xml</slide>

<!-- PHP - IMPROVEMENTS -->
<slide>slides/time/improvements-timezones.xml</slide>
<slide>slides/time/improvements-more-on-timezones.xml</slide>
<slide>slides/time/default-timezone.xml</slide>
<slide>slides/time/timestamps-suck.xml</slide>

<!-- PHP - CODE EXAMPLES -->
<slide>slides/time/basic-parse-time-new.xml</slide>
<slide>slides/time/date-parse2.xml</slide>
<slide>slides/time/date-parse-from-format3.xml</slide>
<slide>slides/time/date-parse-from-format2.xml</slide>

<!-- DATE EXAMPLES -->
<slide>slides/time/date-modify.xml</slide>
<slide>slides/time/date-modify-immutable1.xml</slide>
<slide>slides/time/date-modify-immutable2.xml</slide>
<slide>slides/time/timezone-object-1.xml</slide>
<slide>slides/time/date-timezone.xml</slide>
<slide>slides/time/timezone-utilities-3.xml</slide>

<!-- INTERVALS and PERIODS -->
<slide>slides/time/intervals.xml</slide>
<slide>slides/time/intervals-2.xml</slide>
<slide>slides/time/relative-month.xml</slide>
<slide>slides/time/relative-month3.xml</slide>
<slide>slides/time/period-2.xml</slide>

<!-- STORING in DATABASE -->
<!-- OLD:
<slide>slides/time/in-database1.xml</slide>
<slide>slides/time/in-database2.xml</slide>
<slide>slides/time/in-database3.xml</slide>
-->
<slide>slides/time/in-database4.xml</slide>
<slide>slides/time/in-mdb1.xml</slide>

<!-- CALENDARS -->

<!-- EXIT -->
<slide>slides/time/book.xml</slide> <!-- resources -->
<slide>slides/mongodb/questions.xml</slide>
<slide>slides/mongodb/resources.xml</slide> <!-- resources -->
</presentation>

0 comments on commit d21dcfe

Please sign in to comment.