-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
341 lines (333 loc) · 11.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Modele Devoxx FR 2017 reveal.js</title>
<link rel="stylesheet" href="css/reveal.css">
<!--link rel="stylesheet" href="css/theme/black.css" id="theme"-->
<link rel="stylesheet" href="css/theme/devoxxfr.css" id="theme">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-state="intro">
<h1>Devoxx France 2017<br />L’enfer de l’objet Date JS</h1>
<p style="margin-top:30%">Bounkong Khamphousone <a href="http://twitter.com/tibounk">@tibounk</a></p>
</section>
<section>
<h2>Démonstration du problème</h2>
<table class="reveal">
<thead>
<tr>
<th>Client JS</th>
<th>Serveur JVM</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<ul>
<li>Angular 2</li>
<li>Native Date</li>
<li>mydatepicker</li>
</ul>
</td>
<td style="vertical-align:top">
Akka-HTTP
</td>
</tr>
</tbody>
</table>
<aside class="notes">
Présentation du problème initial avec la date JS.
</aside>
</section>
<section data-state="intro">
<h2>Qu'est-ce que <b>Date</b> ?</h2>
</section>
<section data-state="epoch">
<h2>Epoch</h2>
<p id="timeElapsed" style="margin-top:15%; font-size: 100px" align="center"></p>
<aside class="notes">
Nombre de millisecondes écoulées depuis le 1er janvier 1970 UTC à 00:00
</aside>
</section>
<section data-state="timezone">
<h2>Gestion des timezones</h2>
<table class="reveal" style="margin-top:7%">
<thead>
<tr>
<th>Zone</th>
<th>Heure</th>
<th>Décalage</th>
</tr>
</thead>
<tr>
<td>New-York</td>
<td id="newYorkTime"></td>
<td id="newYorkTZ"></td>
</tr>
<tr>
<td>Londres</td>
<td id="londonTime"></td>
<td id="londonTZ"></td>
</tr>
<tr>
<td>Paris</td>
<td id="parisTime"></td>
<td id="parisTZ"></td>
</tr>
<tr>
<td>Inde</td>
<td id="indiaTime"></td>
<td id="indiaTZ"></td>
</tr>
</table>
</section>
<section>
<h2>Heure d'été (France)<br/>Daylight Saving Time (DST)</h2>
<table class="reveal" style="margin-top:7%">
<thead>
<tr>
<th>Année</th>
<th>Heure d'été</th>
<th>Heure d'hiver</th>
</tr>
</thead>
<tr>
<td>2017</td>
<td>Dimanche 26 mars</td>
<td>Dimanche 29 octobre</td>
</tr>
<tr>
<td>2018</td>
<td>Dimanche 25 mars</td>
<td>Dimanche 28 octobre</td>
</tr>
<tr>
<td>2019</td>
<td>Dimanche 31 mars</td>
<td>Dimanche 27 octobre</td>
</tr>
</table>
<aside class="notes">
var d = new Date(1970, 8, 1);<br/>
JSON.stringify(d);
</aside>
</section>
<section>
<h2>ISO-8601</h2>
<p class="fragment" data-fragment-index="1">1980-07-31T23:00:00.000Z</p>
<p class="fragment" data-fragment-index="2"><année>-<mois>-<jour>T<heure>:<min>:<sec>.<ms><Fuseau horaire></p>
<p class="fragment" data-fragment-index="3">Pattern Java : yyyy-MM-dd'T'HH:mm:ss.SSSX</p>
<pre class="fragment" data-fragment-index="4"><code data-trim data-noescape>// Java 7+
String dateStr = "1980-07-31T23:00:00.000Z";
SimpleDateFormat formatterJ7 =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
TimeZone tz = TimeZone.getTimeZone("Europe/Paris");
formatterJ7.setTimeZone(tz);
try {
Date dJ7 = formatterJ7.parse(dateStr);
System.out.println(dJ7);
} catch (ParseException e) {
e.printStackTrace();
}
</code></pre>
<aside class="notes">
val dateStr = "1980-07-31T23:00:00.000Z"<br/>
val formatterJ7 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX")<br/>
val tz = TimeZone.getTimeZone("Europe/Paris")<br/>
formatterJ7.setTimeZone(tz)<br/>
val dJ7 = formatterJ7.parse(dateStr)<br/>
println(dJ7)<br/>
<br/>
<br/>
val dJ8 = ZonedDateTime.parse(dateStr)<br/>
println(dJ8.toInstant.atZone(ZoneId.systemDefault()))
</aside>
</section>
<section>
<h2>ISO 8601</h2>
<pre style="margin-top:15%"><code data-trim data-noescape>// Java 8+
String dateStr = "1980-07-31T23:00:00.000Z";
ZonedDateTime dJ8 = ZonedDateTime.parse(dateStr);
System.out.println(dJ8.withZoneSameInstant(ZoneId.systemDefault()));</code></pre>
</section>
<section>
<h2>DST en JS (ES5)</h2>
<p>
The implementation of ECMAScript should <span style="color:#17ff2e">not try to determine</span> whether the exact time was subject to daylight saving time but
just <span style="color:#17ff2e">whether daylight saving time would have been in effect</span> if the current daylight saving time algorithm had been used at the time.
This <span style="color:#17ff2e">avoids complications</span> such as taking into account the <span style="color:#17ff2e">years that the locale observed daylight saving time year round.</span></p>
</section>
<section>
<h2>DST en JS (ES2016)</h2>
<p>An implementation dependent algorithm using best available information on time zones to determine the local daylight saving time adjustment DaylightSavingTA(t),
measured in milliseconds. An implementation of ECMAScript is expected to make its best effort to determine the local daylight saving time adjustment.</p>
<p><b>Note</b> : <span style="color:#17ff2e">It is recommended that implementations use the time zone information of the IANA Time Zone Database</span> http://www.iana.org/time-zones/.</p>
</section>
<section>
<h2>JSON.parse</h2>
<p style="margin-top:5%" class="fragment" data-fragment-index="1">JSON.parse("{'my':'json'}")</p>
<p class="fragment" data-fragment-index="2">JSON.parse(texte [, reviver])</p>
<pre class="fragment" data-fragment-index="2"><code data-trim data-noescape>JSON.parse('{"p": 5}', (key, value) =>
if (typeof value === 'number') {
return value * 2; // renvoie value * 2 pour les nombres
}
return value; // pour le reste, la valeur est inchangée
);
// { p: 10 }</code></pre>
</section>
<section>
<h2>JSON.stringify</h2>
<p class="fragment" data-fragment-index="1">JSON.stringify({'my':'json'})</p>
<p class="fragment" data-fragment-index="2">JSON.stringify(value [, remplaçant [, espace]])</p>
<pre class="fragment" data-fragment-index="2"><code data-trim data-noescape>function remplaçant(clé, valeur) {
if (typeof valeur === "string") {
return undefined;
}
return valeur;
}
var toto = {fondation: "Mozilla", modèle: "boîte",
semaine: 45, transport: "bus", mois: 7};
console.log(JSON.stringify(toto, remplaçant));
// {"semaine":45, "mois":7}</code></pre>
<p class="fragment" data-fragment-index="3"><objet>.toJSON()</p>
</section>
<section>
<h2>Démo client JS | serveur JVM</h2>
<table class="reveal">
<thead>
<tr>
<th>Client</th>
<th>Serveur</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<ul>
<li>Angular 2</li>
<li>moment</li>
<li>moment-timezone</li>
<li>mydatepicker</li>
</ul>
</td>
<td style="vertical-align:top">
Akka-HTTP
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h2>Démo client JVM | serveur JS</h2>
<table class="reveal">
<thead>
<tr>
<th>Client</th>
<th>Serveur</th>
</tr>
</thead>
<tbody>
<tr>
<td style="vertical-align:top">
Akka-HTTP
</td>
<td>
<ul>
<li>Node JS</li>
<li>moment</li>
<li>moment-timezone</li>
<li>express</li>
<li>body-parser</li>
</ul>
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h2>Choix du type</h2>
<table style="margin-top:7%">
<thead>
<tr>
<th>Timezone</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>Non</td>
<td>String,<br/>LocalDate</td>
</tr>
<tr>
<td>Oui</td>
<td>ZonedDateTime en ajustant la zone,<br/>LocalDateTime convertie depuis un ZonedDateTime</td>
</tr>
</tbody>
</table>
</section>
<section>
<h2>Pour en savoir plus</h2>
<ul>
<li><a href="http://es5.github.io/#x15.9.1.8">Spec ES5</a></li>
<li><a href="http://www.ecma-international.org/ecma-262/7.0/index.html#sec-daylight-saving-time-adjustment">ES2016</a></li>
<li><a href="https://www.iana.org/time-zones">IANA</a></li>
<li><a href="https://momentjs.com/">MomentJS</a></li>
<li><a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/JSON/parse">JSON.Parse</a></li>
<li><a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/JSON/stringify">JSON.Stringify</a></li>
</ul>
</section>
<section data-state="intro">
<h1>Questions ?</h2>
<p style="margin-top:13%; text-align:center; font-size:50px">La présentation et les codes se trouvent sur github : <br/>https://github.com/tiboun/date-devoxx2017</p>
</section>
</div>
<div class="footer">
<p>#DevoxxFR</p>
<span>
<img align="right" src="../images/logos Devoxx France/logo-texte-devoxx-france-400.png" />
<img align="right" src="images/ebiznext/logo.png" />
</span>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script src="js/slides.js"></script>
<script src="js/moment.min.js"></script>
<script src="js/moment-timezone-with-data.min.js"></script>
<script src="js/lodash.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
history: true,
center: false,
controls: false,
progress: true,
width: 1280,
height: 720,
slideNumber: true,
margin: 0.0,
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>