com presentations: Longhorn PHP date/time talk, now with Quiz: slides/time/basic-parse-time-new.xml slides/time/date-modify-immutable1.xml
slides/time/date-modify-immutable2.xml slides/time/date-modify.xml slides/time/date-parse2.xml slides/time/default-timezone.xml
slides/time/in-database4.xml slides/time/in-mdb1.xml slides/time/intervals-2.xml slides/time/intervals.xml slides/time/period-2.xml
slides/time/queries.jpg slides/time/quiz.xml slides
| From: | Derick Rethans | Date: | Fri, 20 Apr 2018 19:54:56 +0000 |
| Subject: | com presentations: Longhorn PHP date/time talk, now with Quiz: slides/time/basic-parse-time-new.xml slides/time/date-modify-immutable1.xml slides/time/date-modify-immutable2.xml slides/time/date-modify.xml slides/time/date-parse2.xml slides/time/default-timezone.xml slides/time/in-database4.xml slides/time/in-mdb1.xml slides/time/intervals-2.xml slides/time/intervals.xml slides/time/period-2.xml slides/time/queries.jpg slides/time/quiz.xml slides |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-2272@lists.php.net to get a copy of this message | ||
Commit: d21dcfe101a63c71f8f23a1237eaaf9e63e653e5
Author: Derick Rethans <github@derickrethans.nl> Fri, 20 Apr 2018 14:54:56 -0500
Parents: 187627223a90d8f74717f3dee91ac3124332fc07
Branches: master
Link: http://git.php.net/?p=presentations.git;a=commitdiff;h=d21dcfe101a63c71f8f23a1237eaaf9e63e653e5
Log:
Longhorn PHP date/time talk, now with Quiz
Changed paths:
M slides/time/basic-parse-time-new.xml
M slides/time/date-modify-immutable1.xml
M slides/time/date-modify-immutable2.xml
M slides/time/date-modify.xml
M slides/time/date-parse2.xml
M slides/time/default-timezone.xml
M slides/time/in-database4.xml
A slides/time/in-mdb1.xml
M slides/time/intervals-2.xml
M slides/time/intervals.xml
M slides/time/period-2.xml
A slides/time/queries.jpg
A slides/time/quiz.xml
M slides/time/relative-month.xml
M slides/time/relative-month3.xml
M slides/time/timestamps-suck.xml
A time-longhorn18.xml
diff --git a/slides/time/basic-parse-time-new.xml b/slides/time/basic-parse-time-new.xml index bffa53e..d45a761 100644 --- a/slides/time/basic-parse-time-new.xml +++ b/slides/time/basic-parse-time-new.xml @@ -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/> @@ -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/> diff --git a/slides/time/date-modify-immutable1.xml b/slides/time/date-modify-immutable1.xml index 2c63a77..5c02e09 100644 --- a/slides/time/date-modify-immutable1.xml +++ b/slides/time/date-modify-immutable1.xml @@ -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"; diff --git a/slides/time/date-modify-immutable2.xml b/slides/time/date-modify-immutable2.xml index b0439b0..5339756 100644 --- a/slides/time/date-modify-immutable2.xml +++ b/slides/time/date-modify-immutable2.xml @@ -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"; diff --git a/slides/time/date-modify.xml b/slides/time/date-modify.xml index 6cfd505..ae8229f 100644 --- a/slides/time/date-modify.xml +++ b/slides/time/date-modify.xml @@ -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"); @@ -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> diff --git a/slides/time/date-parse2.xml b/slides/time/date-parse2.xml index da78534..dc867d0 100644 --- a/slides/time/date-parse2.xml +++ b/slides/time/date-parse2.xml @@ -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'], " "; diff --git a/slides/time/default-timezone.xml b/slides/time/default-timezone.xml index dcaca11..a769a4d 100644 --- a/slides/time/default-timezone.xml +++ b/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> diff --git a/slides/time/in-database4.xml b/slides/time/in-database4.xml index df8532d..0d22e00 100644 --- a/slides/time/in-database4.xml +++ b/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> diff --git a/slides/time/in-mdb1.xml b/slides/time/in-mdb1.xml new file mode 100644 index 0000000..0a1d4cd --- /dev/null +++ b/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> diff --git a/slides/time/intervals-2.xml b/slides/time/intervals-2.xml index 8cb07a9..16902f2 100644 --- a/slides/time/intervals-2.xml +++ b/slides/time/intervals-2.xml @@ -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" ); @@ -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> diff --git a/slides/time/intervals.xml b/slides/time/intervals.xml index a57b1a4..cc32abd 100644 --- a/slides/time/intervals.xml +++ b/slides/time/intervals.xml @@ -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 diff --git a/slides/time/period-2.xml b/slides/time/period-2.xml index ed25904..b89277f 100644 --- a/slides/time/period-2.xml +++ b/slides/time/period-2.xml @@ -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 diff --git a/slides/time/queries.jpg b/slides/time/queries.jpg new file mode 100644 index 0000000..91a4b25 Binary files /dev/null and b/slides/time/queries.jpg differ diff --git a/slides/time/quiz.xml b/slides/time/quiz.xml new file mode 100644 index 0000000..3dba512 --- /dev/null +++ b/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 hours*</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">each day is *23, 24 or 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 or 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 or 366* days</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">everybody understands what *PI 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 hour* offsets from UTC</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">timezones are *half 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 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 least a year* in advance</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">DST rules are announced *in advance*</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">PST is *Pacific Standard 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> diff --git a/slides/time/relative-month.xml b/slides/time/relative-month.xml index ee5fddf..9de0036 100644 --- a/slides/time/relative-month.xml +++ b/slides/time/relative-month.xml @@ -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> diff --git a/slides/time/relative-month3.xml b/slides/time/relative-month3.xml index 7842923..bb804b4 100644 --- a/slides/time/relative-month3.xml +++ b/slides/time/relative-month3.xml @@ -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> diff --git a/slides/time/timestamps-suck.xml b/slides/time/timestamps-suck.xml index 263cf84..c6deae5 100644 --- a/slides/time/timestamps-suck.xml +++ b/slides/time/timestamps-suck.xml @@ -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> diff --git a/time-longhorn18.xml b/time-longhorn18.xml new file mode 100644 index 0000000..34643bd --- /dev/null +++ b/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>
diff --git a/slides/time/basic-parse-time-new.xml b/slides/time/basic-parse-time-new.xml index bffa53e..d45a761 100644 --- a/slides/time/basic-parse-time-new.xml +++ b/slides/time/basic-parse-time-new.xml @@ -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/> @@ -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/> diff --git a/slides/time/date-modify-immutable1.xml b/slides/time/date-modify-immutable1.xml index 2c63a77..5c02e09 100644 --- a/slides/time/date-modify-immutable1.xml +++ b/slides/time/date-modify-immutable1.xml @@ -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"; diff --git a/slides/time/date-modify-immutable2.xml b/slides/time/date-modify-immutable2.xml index b0439b0..5339756 100644 --- a/slides/time/date-modify-immutable2.xml +++ b/slides/time/date-modify-immutable2.xml @@ -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"; diff --git a/slides/time/date-modify.xml b/slides/time/date-modify.xml index 6cfd505..ae8229f 100644 --- a/slides/time/date-modify.xml +++ b/slides/time/date-modify.xml @@ -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"); @@ -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> diff --git a/slides/time/date-parse2.xml b/slides/time/date-parse2.xml index da78534..dc867d0 100644 --- a/slides/time/date-parse2.xml +++ b/slides/time/date-parse2.xml @@ -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'], " "; diff --git a/slides/time/default-timezone.xml b/slides/time/default-timezone.xml index dcaca11..a769a4d 100644 --- a/slides/time/default-timezone.xml +++ b/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> diff --git a/slides/time/in-database4.xml b/slides/time/in-database4.xml index df8532d..0d22e00 100644 --- a/slides/time/in-database4.xml +++ b/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> diff --git a/slides/time/in-mdb1.xml b/slides/time/in-mdb1.xml new file mode 100644 index 0000000..0a1d4cd --- /dev/null +++ b/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> diff --git a/slides/time/intervals-2.xml b/slides/time/intervals-2.xml index 8cb07a9..16902f2 100644 --- a/slides/time/intervals-2.xml +++ b/slides/time/intervals-2.xml @@ -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" ); @@ -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> diff --git a/slides/time/intervals.xml b/slides/time/intervals.xml index a57b1a4..cc32abd 100644 --- a/slides/time/intervals.xml +++ b/slides/time/intervals.xml @@ -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 diff --git a/slides/time/period-2.xml b/slides/time/period-2.xml index ed25904..b89277f 100644 --- a/slides/time/period-2.xml +++ b/slides/time/period-2.xml @@ -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 diff --git a/slides/time/queries.jpg b/slides/time/queries.jpg new file mode 100644 index 0000000..91a4b25 Binary files /dev/null and b/slides/time/queries.jpg differ diff --git a/slides/time/quiz.xml b/slides/time/quiz.xml new file mode 100644 index 0000000..3dba512 --- /dev/null +++ b/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 hours*</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">each day is *23, 24 or 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 or 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 or 366* days</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">everybody understands what *PI 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 hour* offsets from UTC</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">timezones are *half 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 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 least a year* in advance</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">DST rules are announced *in advance*</blurb></div> +<div effect="fade-in-out"><blurb class="big-centre">PST is *Pacific Standard 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> diff --git a/slides/time/relative-month.xml b/slides/time/relative-month.xml index ee5fddf..9de0036 100644 --- a/slides/time/relative-month.xml +++ b/slides/time/relative-month.xml @@ -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> diff --git a/slides/time/relative-month3.xml b/slides/time/relative-month3.xml index 7842923..bb804b4 100644 --- a/slides/time/relative-month3.xml +++ b/slides/time/relative-month3.xml @@ -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> diff --git a/slides/time/timestamps-suck.xml b/slides/time/timestamps-suck.xml index 263cf84..c6deae5 100644 --- a/slides/time/timestamps-suck.xml +++ b/slides/time/timestamps-suck.xml @@ -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> diff --git a/time-longhorn18.xml b/time-longhorn18.xml new file mode 100644 index 0000000..34643bd --- /dev/null +++ b/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>