SlideShare a Scribd company logo
ZombieTime – JSR 310 for the Undead
Stephen Chin (@steveonjava)
Java Technology Evangelist
JavaOne Conference Chair
https://www.flickr.com/photos/philippeleroyer/4071842319/
We just want to fit in
3
https://www.flickr.com/photos/moira_fee/5632351014/
But humans are scared of us!
4
Is it just because we eat brains?
https://www.flickr.com/photos/dwilliss/7861599590/
5
https://www.flickr.com/photos/jeepersmedia/11883875415/
They quarantine us…
6
https://www.flickr.com/photos/nichpics/10628256503/
And attack us with weapons…
But when it is us vs. them…
https://www.flickr.com/photos/icedsoul/4511648609/in/photostream/
8
Humans don't stand a chance!
https://www.flickr.com/photos/icedsoul/4470494133/
JSR 310, a New Weapon Against the Humans!
• Our researchers have come up
with a new weapon against the
humans!
– Modern API – Zombies type slow, so
we need a fluent API with easy
conversions
– Thread safe – Don't get caught in a
deadlock with armed humans!
– Simplified Time Zone Handling –
Coordinated global attacks!
9https://www.flickr.com/photos/soul_stealer/8249718101/
Stephen Colebourne
Roger Riggs
Don't repeat this failure…
• // hit the humans while they are celebrating!
• Date attackDate = new Date(2013, 12, 25);
10
In the year 3913
https://www.flickr.com/photos/frogdna/6948427148/
+1900
0-based
(No Range
Checking!)
11
Why are we still using
escalators 2000 years in
the future?
I think we are
surrounded…
I hope you took your
Zombie shot, junior.
January 25th, 3914 : Failed Zombie Trooper Invasion
https://www.flickr.com/photos/starwarsblog/516181007/
ZombieTime – Undead Trainer for JSR 310
12
Basic Concepts
• LocalDate, LocalTime, LocalDateTime
– Represents a calendar date, time, or both
• Instant
– Amount of time since the epoch – ideal for timestamps and calculations
• Period
– A span of time between two dates (goes well with LocalDateTime)
• Duration
– A precise span of time (goes well with Instants)
13
Creating Dates and Times
• Now
– LocalDate.now()
• Static
– LocalDate.of(2013, Month.DECEMBER, 25) // Use the enums!
– LocalTime.of(11, 30, 5, 999_999_999) // Time to go to work…
– LocalDateTime.of(2013, Month.DECEMBER, 25, 11, 30, 5, 999_999_999) // Even on
Christmas
• Parsing
– LocalDate.parse()
• Conversion
– new Date().toInstant()
– Calendar.getInstance().toInstant()
14
PixelatedClock
Timeline clockTimeline = new Timeline(
new KeyFrame(Duration.millis(1),
actionEvent -> {
LocalTime now = LocalTime.now();
}));
15
16
Formatting Dates and Times
• Constants
– DateTimeFormatter.BASIC_ISO_DATE // '2011-12-03+01:00'
– DateTimeFormatter.ISO_TIME // '10:15:30+01:00'
– DateTimeFormatter.ISO_DATE_TIME // '2011-12-03T10:15:30+01:00[Europe/Paris]'
– DateTimeFormatter.ISO_WEEK_DATE // 2012-W48-6'
• Localized Formatters
– DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)
• Strings
– date.toString("d MMM uuuu") // '25 Dec 2014'
• Formatters are immutable and thread-safe for reuse!
17
Localized PixelatedClock
DateTimeFormatter clockFormat =
DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
Timeline clockTimeline = new Timeline(
new KeyFrame(Duration.millis(1),
actionEvent -> {
setText(now.format(clockFormat));
}));
18
19
20
21
https://www.flickr.com/photos/rosenwald/4534092922/
I HATE SUNBURN!
Using LocalTime/LocalDate
• Comparing Times/Dates:
– time.isBefore(LocalTime.NOON) // before noon
– date.isAfter(LocalDate.ofYearDay(2014, 365 / 2)) // appx. halfway through the year
• Year Info:
– date.getYear()
– date.getDayOfYear()
– date.lengthOfYear()
– date.isLeapYear()
• Time Info:
– time.getHour() / time.getMinute() / time.getSecond() / time.getNano()
22
Hide from the sunlight!
public BooleanProperty isNight = new
SimpleBooleanProperty();
isNight.setValue(now.isAfter(LocalTime.of(6, 0)) &&
now.isBefore(LocalTime.of(19, 0)));
underground.bind(Main.pixelatedClock.isNight.not());
23
24
Let's Add Some Villagers!
children.add(new SpriteView.Fred(new Location(8, 2)));
children.add(new SpriteView.Sam(new Location(9, 4)));
children.add(new SpriteView.Ted(new Location(7, 6)));
children.add(new SpriteView.Sarah(new Location(5, 4)));
children.add(new SpriteView.Jenn(new Location(6, 5)));
25
26
Ouch! Don't step
on me
Using Time Zones
Creating ZoneIds:
• zoneId = ZoneId.of("Europe/Paris");
• zoneId = ZoneId.of(ZoneId.SHORT_IDS.get("EST"));
• zoneId = ZoneOffset.ofHours(-8);
Using ZoneIds:
• dateTime.now(zoneId);
• dateTime.atZone(zoneId);
• Clock.system(zoneId);
27
Make it Night!
ZoneId zoneId = ZoneId.of("Europe/London");
LocalTime now = LocalTime.now(zoneId);
28
Make it Night! (with a clock)
ZoneId zone = ZoneId.of("Europe/London");
Clock clock = Clock.system(zone);
LocalTime now = LocalTime.now(clock);
29
30
Wait!!! I just want
your brains…
Temporal Adjusters
• Predefined adjustors for common cases
– First or last day of month
• date.with(TemporalAdjusters.firstDayOfMonth())
– First or last day of year
• date.with(TemporalAdjusters.firstDayOfNextYear())
– Last Friday of the month
• date.with(TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY))
• Custom adjusters for your own business logic
31
Friday 13th TimeAdjuster
TemporalAdjuster friday13Adjuster = temporal -> {
if (temporal.get(ChronoField.DAY_OF_MONTH) > 13) temporal =
temporal.plus(1, ChronoUnit.MONTHS);
temporal = temporal.with(ChronoField.DAY_OF_MONTH, 13);
System.out.println("temporal = " + temporal);
while (temporal.get(ChronoField.DAY_OF_WEEK) !=
DayOfWeek.FRIDAY.getValue()) {
temporal = temporal.plus(1, ChronoUnit.MONTHS);
System.out.println("temporal = " + temporal);
}
return temporal;
};
32
Zombified picture here…
33
34
https://www.flickr.com/photos/s1mone/1833002341
Stephen Chin
tweet: @steveonjava
blog: http://steveonjava.com
nighthacking.com
Real Geeks
Live Hacking
NightHacking Tour
Safe Harbor Statement
The preceding is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
36
Zombie Time - JSR 310 for the Undead

More Related Content

Viewers also liked

Internet of Things Magic Show
Internet of Things Magic ShowInternet of Things Magic Show
Internet of Things Magic Show
Stephen Chin
 
Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)
Stephen Chin
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the Cloud
Stephen Chin
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and VisageHacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Stephen Chin
 
Raspberry Pi Gaming 4 Kids - Dutch Version
Raspberry Pi Gaming 4 Kids - Dutch VersionRaspberry Pi Gaming 4 Kids - Dutch Version
Raspberry Pi Gaming 4 Kids - Dutch Version
Stephen Chin
 
RetroPi Handheld Raspberry Pi Gaming Console
RetroPi Handheld Raspberry Pi Gaming ConsoleRetroPi Handheld Raspberry Pi Gaming Console
RetroPi Handheld Raspberry Pi Gaming Console
Stephen Chin
 
OpenJFX on Android and Devices
OpenJFX on Android and DevicesOpenJFX on Android and Devices
OpenJFX on Android and Devices
Stephen Chin
 
JavaFX on Mobile (by Johan Vos)
JavaFX on Mobile (by Johan Vos)JavaFX on Mobile (by Johan Vos)
JavaFX on Mobile (by Johan Vos)
Stephen Chin
 
Raspberry Pi Gaming 4 Kids (Devoxx4Kids)
Raspberry Pi Gaming 4 Kids (Devoxx4Kids)Raspberry Pi Gaming 4 Kids (Devoxx4Kids)
Raspberry Pi Gaming 4 Kids (Devoxx4Kids)
Stephen Chin
 
Confessions of a Former Agile Methodologist (JFrog Edition)
Confessions of a Former Agile Methodologist (JFrog Edition)Confessions of a Former Agile Methodologist (JFrog Edition)
Confessions of a Former Agile Methodologist (JFrog Edition)
Stephen Chin
 
Oracle IoT Kids Workshop
Oracle IoT Kids WorkshopOracle IoT Kids Workshop
Oracle IoT Kids Workshop
Stephen Chin
 
Java 8 for Tablets, Pis, and Legos
Java 8 for Tablets, Pis, and LegosJava 8 for Tablets, Pis, and Legos
Java 8 for Tablets, Pis, and Legos
Stephen Chin
 
Devoxx4Kids NAO Workshop
Devoxx4Kids NAO WorkshopDevoxx4Kids NAO Workshop
Devoxx4Kids NAO Workshop
Stephen Chin
 
Devoxx4Kids Lego Workshop
Devoxx4Kids Lego WorkshopDevoxx4Kids Lego Workshop
Devoxx4Kids Lego Workshop
Stephen Chin
 

Viewers also liked (14)

Internet of Things Magic Show
Internet of Things Magic ShowInternet of Things Magic Show
Internet of Things Magic Show
 
Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the Cloud
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and VisageHacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
 
Raspberry Pi Gaming 4 Kids - Dutch Version
Raspberry Pi Gaming 4 Kids - Dutch VersionRaspberry Pi Gaming 4 Kids - Dutch Version
Raspberry Pi Gaming 4 Kids - Dutch Version
 
RetroPi Handheld Raspberry Pi Gaming Console
RetroPi Handheld Raspberry Pi Gaming ConsoleRetroPi Handheld Raspberry Pi Gaming Console
RetroPi Handheld Raspberry Pi Gaming Console
 
OpenJFX on Android and Devices
OpenJFX on Android and DevicesOpenJFX on Android and Devices
OpenJFX on Android and Devices
 
JavaFX on Mobile (by Johan Vos)
JavaFX on Mobile (by Johan Vos)JavaFX on Mobile (by Johan Vos)
JavaFX on Mobile (by Johan Vos)
 
Raspberry Pi Gaming 4 Kids (Devoxx4Kids)
Raspberry Pi Gaming 4 Kids (Devoxx4Kids)Raspberry Pi Gaming 4 Kids (Devoxx4Kids)
Raspberry Pi Gaming 4 Kids (Devoxx4Kids)
 
Confessions of a Former Agile Methodologist (JFrog Edition)
Confessions of a Former Agile Methodologist (JFrog Edition)Confessions of a Former Agile Methodologist (JFrog Edition)
Confessions of a Former Agile Methodologist (JFrog Edition)
 
Oracle IoT Kids Workshop
Oracle IoT Kids WorkshopOracle IoT Kids Workshop
Oracle IoT Kids Workshop
 
Java 8 for Tablets, Pis, and Legos
Java 8 for Tablets, Pis, and LegosJava 8 for Tablets, Pis, and Legos
Java 8 for Tablets, Pis, and Legos
 
Devoxx4Kids NAO Workshop
Devoxx4Kids NAO WorkshopDevoxx4Kids NAO Workshop
Devoxx4Kids NAO Workshop
 
Devoxx4Kids Lego Workshop
Devoxx4Kids Lego WorkshopDevoxx4Kids Lego Workshop
Devoxx4Kids Lego Workshop
 

Similar to Zombie Time - JSR 310 for the Undead

Date object.pptx date and object v
Date object.pptx date and object        vDate object.pptx date and object        v
Date object.pptx date and object v
22x026
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4Introduction to Date and Time API 4
Introduction to Date and Time API 4
Kenji HASUNUMA
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4Introduction to Date and Time API 4
Introduction to Date and Time API 4
Kenji HASUNUMA
 
Data Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing ItData Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing It
kanaugust
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3
Kenji HASUNUMA
 
JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8
Serhii Kartashov
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3
Kenji HASUNUMA
 
Lesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptxLesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptx
LagamaPasala
 
Date and Time MomentJS Edition
Date and Time MomentJS EditionDate and Time MomentJS Edition
Date and Time MomentJS Edition
Maggie Pint
 
Sensors Aren't Enough
Sensors Aren't EnoughSensors Aren't Enough
Sensors Aren't Enough
C4Media
 
That Conference Date and Time
That Conference Date and TimeThat Conference Date and Time
That Conference Date and Time
Maggie Pint
 
05 Java Language And OOP Part V
05 Java Language And OOP Part V05 Java Language And OOP Part V
05 Java Language And OOP Part V
Hari Christian
 
Date and Time Odds Ends Oddities
Date and Time Odds Ends OdditiesDate and Time Odds Ends Oddities
Date and Time Odds Ends Oddities
Maggie Pint
 
WEB222-lecture-4.pptx
WEB222-lecture-4.pptxWEB222-lecture-4.pptx
WEB222-lecture-4.pptx
RohitSharma318779
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
Ganesh Samarthyam
 
What Year Is It: things you shouldn't do with timezones
What Year Is It: things you shouldn't do with timezonesWhat Year Is It: things you shouldn't do with timezones
What Year Is It: things you shouldn't do with timezones
Aram Dulyan
 
Fun times with ruby
Fun times with rubyFun times with ruby
Fun times with ruby
Geoff Harcourt
 
Chapter ii(coding)
Chapter ii(coding)Chapter ii(coding)
Chapter ii(coding)
Chhom Karath
 
A JSR-310 Date: Beyond JODA Time
A JSR-310 Date: Beyond JODA TimeA JSR-310 Date: Beyond JODA Time
A JSR-310 Date: Beyond JODA Time
Daniel Sobral
 
From the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by StepFrom the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by Step
Igalia
 

Similar to Zombie Time - JSR 310 for the Undead (20)

Date object.pptx date and object v
Date object.pptx date and object        vDate object.pptx date and object        v
Date object.pptx date and object v
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4Introduction to Date and Time API 4
Introduction to Date and Time API 4
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4Introduction to Date and Time API 4
Introduction to Date and Time API 4
 
Data Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing ItData Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing It
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3
 
JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3
 
Lesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptxLesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptx
 
Date and Time MomentJS Edition
Date and Time MomentJS EditionDate and Time MomentJS Edition
Date and Time MomentJS Edition
 
Sensors Aren't Enough
Sensors Aren't EnoughSensors Aren't Enough
Sensors Aren't Enough
 
That Conference Date and Time
That Conference Date and TimeThat Conference Date and Time
That Conference Date and Time
 
05 Java Language And OOP Part V
05 Java Language And OOP Part V05 Java Language And OOP Part V
05 Java Language And OOP Part V
 
Date and Time Odds Ends Oddities
Date and Time Odds Ends OdditiesDate and Time Odds Ends Oddities
Date and Time Odds Ends Oddities
 
WEB222-lecture-4.pptx
WEB222-lecture-4.pptxWEB222-lecture-4.pptx
WEB222-lecture-4.pptx
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
 
What Year Is It: things you shouldn't do with timezones
What Year Is It: things you shouldn't do with timezonesWhat Year Is It: things you shouldn't do with timezones
What Year Is It: things you shouldn't do with timezones
 
Fun times with ruby
Fun times with rubyFun times with ruby
Fun times with ruby
 
Chapter ii(coding)
Chapter ii(coding)Chapter ii(coding)
Chapter ii(coding)
 
A JSR-310 Date: Beyond JODA Time
A JSR-310 Date: Beyond JODA TimeA JSR-310 Date: Beyond JODA Time
A JSR-310 Date: Beyond JODA Time
 
From the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by StepFrom the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by Step
 

More from Stephen Chin

DevOps Tools for Java Developers v2
DevOps Tools for Java Developers v2DevOps Tools for Java Developers v2
DevOps Tools for Java Developers v2
Stephen Chin
 
10 Ways Everyone Can Support the Java Community
10 Ways Everyone Can Support the Java Community10 Ways Everyone Can Support the Java Community
10 Ways Everyone Can Support the Java Community
Stephen Chin
 
Java Clients and JavaFX: The Definitive Guide
Java Clients and JavaFX: The Definitive GuideJava Clients and JavaFX: The Definitive Guide
Java Clients and JavaFX: The Definitive Guide
Stephen Chin
 
DevOps Tools for Java Developers
DevOps Tools for Java DevelopersDevOps Tools for Java Developers
DevOps Tools for Java Developers
Stephen Chin
 
Java Clients and JavaFX - Presented to LJC
Java Clients and JavaFX - Presented to LJCJava Clients and JavaFX - Presented to LJC
Java Clients and JavaFX - Presented to LJC
Stephen Chin
 
LUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi HackingLUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi Hacking
Stephen Chin
 
Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5
Stephen Chin
 
JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)
JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)
JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)
Stephen Chin
 
JavaFX 2 Using the Spring Framework
JavaFX 2 Using the Spring FrameworkJavaFX 2 Using the Spring Framework
JavaFX 2 Using the Spring Framework
Stephen Chin
 

More from Stephen Chin (9)

DevOps Tools for Java Developers v2
DevOps Tools for Java Developers v2DevOps Tools for Java Developers v2
DevOps Tools for Java Developers v2
 
10 Ways Everyone Can Support the Java Community
10 Ways Everyone Can Support the Java Community10 Ways Everyone Can Support the Java Community
10 Ways Everyone Can Support the Java Community
 
Java Clients and JavaFX: The Definitive Guide
Java Clients and JavaFX: The Definitive GuideJava Clients and JavaFX: The Definitive Guide
Java Clients and JavaFX: The Definitive Guide
 
DevOps Tools for Java Developers
DevOps Tools for Java DevelopersDevOps Tools for Java Developers
DevOps Tools for Java Developers
 
Java Clients and JavaFX - Presented to LJC
Java Clients and JavaFX - Presented to LJCJava Clients and JavaFX - Presented to LJC
Java Clients and JavaFX - Presented to LJC
 
LUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi HackingLUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi Hacking
 
Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5
 
JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)
JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)
JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)
 
JavaFX 2 Using the Spring Framework
JavaFX 2 Using the Spring FrameworkJavaFX 2 Using the Spring Framework
JavaFX 2 Using the Spring Framework
 

Recently uploaded

20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 

Recently uploaded (20)

20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 

Zombie Time - JSR 310 for the Undead

  • 1. ZombieTime – JSR 310 for the Undead Stephen Chin (@steveonjava) Java Technology Evangelist JavaOne Conference Chair
  • 4. 4 Is it just because we eat brains? https://www.flickr.com/photos/dwilliss/7861599590/
  • 7. But when it is us vs. them… https://www.flickr.com/photos/icedsoul/4511648609/in/photostream/
  • 8. 8 Humans don't stand a chance! https://www.flickr.com/photos/icedsoul/4470494133/
  • 9. JSR 310, a New Weapon Against the Humans! • Our researchers have come up with a new weapon against the humans! – Modern API – Zombies type slow, so we need a fluent API with easy conversions – Thread safe – Don't get caught in a deadlock with armed humans! – Simplified Time Zone Handling – Coordinated global attacks! 9https://www.flickr.com/photos/soul_stealer/8249718101/ Stephen Colebourne Roger Riggs
  • 10. Don't repeat this failure… • // hit the humans while they are celebrating! • Date attackDate = new Date(2013, 12, 25); 10 In the year 3913 https://www.flickr.com/photos/frogdna/6948427148/ +1900 0-based (No Range Checking!)
  • 11. 11 Why are we still using escalators 2000 years in the future? I think we are surrounded… I hope you took your Zombie shot, junior. January 25th, 3914 : Failed Zombie Trooper Invasion https://www.flickr.com/photos/starwarsblog/516181007/
  • 12. ZombieTime – Undead Trainer for JSR 310 12
  • 13. Basic Concepts • LocalDate, LocalTime, LocalDateTime – Represents a calendar date, time, or both • Instant – Amount of time since the epoch – ideal for timestamps and calculations • Period – A span of time between two dates (goes well with LocalDateTime) • Duration – A precise span of time (goes well with Instants) 13
  • 14. Creating Dates and Times • Now – LocalDate.now() • Static – LocalDate.of(2013, Month.DECEMBER, 25) // Use the enums! – LocalTime.of(11, 30, 5, 999_999_999) // Time to go to work… – LocalDateTime.of(2013, Month.DECEMBER, 25, 11, 30, 5, 999_999_999) // Even on Christmas • Parsing – LocalDate.parse() • Conversion – new Date().toInstant() – Calendar.getInstance().toInstant() 14
  • 15. PixelatedClock Timeline clockTimeline = new Timeline( new KeyFrame(Duration.millis(1), actionEvent -> { LocalTime now = LocalTime.now(); })); 15
  • 16. 16
  • 17. Formatting Dates and Times • Constants – DateTimeFormatter.BASIC_ISO_DATE // '2011-12-03+01:00' – DateTimeFormatter.ISO_TIME // '10:15:30+01:00' – DateTimeFormatter.ISO_DATE_TIME // '2011-12-03T10:15:30+01:00[Europe/Paris]' – DateTimeFormatter.ISO_WEEK_DATE // 2012-W48-6' • Localized Formatters – DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT) • Strings – date.toString("d MMM uuuu") // '25 Dec 2014' • Formatters are immutable and thread-safe for reuse! 17
  • 18. Localized PixelatedClock DateTimeFormatter clockFormat = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); Timeline clockTimeline = new Timeline( new KeyFrame(Duration.millis(1), actionEvent -> { setText(now.format(clockFormat)); })); 18
  • 19. 19
  • 20. 20
  • 22. Using LocalTime/LocalDate • Comparing Times/Dates: – time.isBefore(LocalTime.NOON) // before noon – date.isAfter(LocalDate.ofYearDay(2014, 365 / 2)) // appx. halfway through the year • Year Info: – date.getYear() – date.getDayOfYear() – date.lengthOfYear() – date.isLeapYear() • Time Info: – time.getHour() / time.getMinute() / time.getSecond() / time.getNano() 22
  • 23. Hide from the sunlight! public BooleanProperty isNight = new SimpleBooleanProperty(); isNight.setValue(now.isAfter(LocalTime.of(6, 0)) && now.isBefore(LocalTime.of(19, 0))); underground.bind(Main.pixelatedClock.isNight.not()); 23
  • 24. 24
  • 25. Let's Add Some Villagers! children.add(new SpriteView.Fred(new Location(8, 2))); children.add(new SpriteView.Sam(new Location(9, 4))); children.add(new SpriteView.Ted(new Location(7, 6))); children.add(new SpriteView.Sarah(new Location(5, 4))); children.add(new SpriteView.Jenn(new Location(6, 5))); 25
  • 27. Using Time Zones Creating ZoneIds: • zoneId = ZoneId.of("Europe/Paris"); • zoneId = ZoneId.of(ZoneId.SHORT_IDS.get("EST")); • zoneId = ZoneOffset.ofHours(-8); Using ZoneIds: • dateTime.now(zoneId); • dateTime.atZone(zoneId); • Clock.system(zoneId); 27
  • 28. Make it Night! ZoneId zoneId = ZoneId.of("Europe/London"); LocalTime now = LocalTime.now(zoneId); 28
  • 29. Make it Night! (with a clock) ZoneId zone = ZoneId.of("Europe/London"); Clock clock = Clock.system(zone); LocalTime now = LocalTime.now(clock); 29
  • 30. 30 Wait!!! I just want your brains…
  • 31. Temporal Adjusters • Predefined adjustors for common cases – First or last day of month • date.with(TemporalAdjusters.firstDayOfMonth()) – First or last day of year • date.with(TemporalAdjusters.firstDayOfNextYear()) – Last Friday of the month • date.with(TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY)) • Custom adjusters for your own business logic 31
  • 32. Friday 13th TimeAdjuster TemporalAdjuster friday13Adjuster = temporal -> { if (temporal.get(ChronoField.DAY_OF_MONTH) > 13) temporal = temporal.plus(1, ChronoUnit.MONTHS); temporal = temporal.with(ChronoField.DAY_OF_MONTH, 13); System.out.println("temporal = " + temporal); while (temporal.get(ChronoField.DAY_OF_WEEK) != DayOfWeek.FRIDAY.getValue()) { temporal = temporal.plus(1, ChronoUnit.MONTHS); System.out.println("temporal = " + temporal); } return temporal; }; 32
  • 35. Stephen Chin tweet: @steveonjava blog: http://steveonjava.com nighthacking.com Real Geeks Live Hacking NightHacking Tour
  • 36. Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 36