16
LJC/JCP Committee Java Dating By James Gough Thursday, 14 July 2011

Java Dating - JSR 310 Lightning Talk

Embed Size (px)

DESCRIPTION

A lightning talk that I presented to the London Java Community on JSR-310

Citation preview

Page 1: Java Dating - JSR 310 Lightning Talk

LJC/JCP CommitteeJava Dating

By James Gough

Thursday, 14 July 2011

Page 2: Java Dating - JSR 310 Lightning Talk

LJC/JCP

• Who am I?

• What is the LJC/JCP?

• Why get involved?

Thursday, 14 July 2011

Page 3: Java Dating - JSR 310 Lightning Talk

Who am I?• James Gough

[email protected]

• Twitter: goughjam

• Java developer for 8 years, 4 years industry experience

• Work at a large investment bank developing Flex and Java

• Run my own company in spare time developing iOS applications

3

Thursday, 14 July 2011

Page 4: Java Dating - JSR 310 Lightning Talk

LJC/JCP• LJC recently elected onto the JCP committee

• JCP (Java Community Process)

• The JCP is the mechanism for developing standard technical specifications for the Java technology

• Interested? Ben Evans @kittylst on twitter, or find me at the bar on Tuesday

4

Thursday, 14 July 2011

Page 5: Java Dating - JSR 310 Lightning Talk

Why get involved?

• Chance to have a say

• Discover more about Java and the inner workings

• Get involved on projects and contribute to Java directly

• Offered to do a lightning talk

• Coming soon: Java memory pub

5

Thursday, 14 July 2011

Page 6: Java Dating - JSR 310 Lightning Talk

Dates?• The thing that's bothering me at the

moment is dating, there’s several things to be aware of:

• Choosing a good restaurant

• What to wear

• ....

6

Thursday, 14 July 2011

Page 7: Java Dating - JSR 310 Lightning Talk

Java Dates

• Java Date and Calendar

• Joda Time

• JSR-310

7

Thursday, 14 July 2011

Page 8: Java Dating - JSR 310 Lightning Talk

Java Date• Java Date has been in the language since January 23, 1996

• Many good discussions about what’s wrong with dates

• Mutability

• Date is a DateTime, but there are other classes for SQL

• No Timezones

• Not easy to use

8

Thursday, 14 July 2011

Page 9: Java Dating - JSR 310 Lightning Talk

Calendar

• Still mutable

• Can’t format a date directly

9

Thursday, 14 July 2011

Page 10: Java Dating - JSR 310 Lightning Talk

Example From It’s High Time @JavaOne 2008

• How many bugs in this code?

Date date = new Date(2007, 12, 13, 16, 40);

TimeZone zone = TimeZone.getInstance("Asia/HongKong");

Calendar cal = new GregorianCalendar(date, zone); DateFormat fm = new SimpleDateFormat("HH:mm Z");String str = fm.format(cal);

10

Thursday, 14 July 2011

Page 11: Java Dating - JSR 310 Lightning Talk

Example From It’s High Time @JavaOne 2008

• 6 bugs in the code!

Date date = new Date(2007, 12, 13, 16, 40);

TimeZone zone = TimeZone.getInstance("Asia/Hong_Kong");

Calendar cal = new GregorianCalendar(date, zone); DateFormat fm = new SimpleDateFormat("HH:mm Z");String str = fm.format(cal);

11

Thursday, 14 July 2011

Page 12: Java Dating - JSR 310 Lightning Talk

Joda Time• Instant

• Moment in time, represented by DateTime. DateTime is immutable

• Interval

• An interval of time from one instant to another. Both end points have same Chronology and TimeZone

• Duration

• Duration of time measured in milliseconds. No timezone of chronology applies

12

Thursday, 14 July 2011

Page 13: Java Dating - JSR 310 Lightning Talk

Joda Time• Period

• A period of time defined in terms of fields (e.g. +1 month)

• Chronology

• A calculation engine supporting complex calendar rules

• In most this can be ignored, important to the internal design, but not to the standard user using ISOChronology

• Timezones

• DateTimeZone zone = DateTimeZone.forID("Europe/London");

13

Thursday, 14 July 2011

Page 14: Java Dating - JSR 310 Lightning Talk

JSR-310• Human/Machine Timelines

• Requirement to have a separation of concerns between human and machine timelines

• DateTime is better thought of as a LocalDateTime and a timezone

• Pluggable Chronology

• Restrict DateTime classes to a single calendar system

• Nulls

• Null means 0 in most cases, ouch!14

Thursday, 14 July 2011

Page 15: Java Dating - JSR 310 Lightning Talk

Getting Involved• ThreeTen is now on GitHub

• Open project that can be contributed to

• A few pull requests have been made since moving to GitHub

• Accept the legal agreement

• Mailing List: [email protected]

15

Thursday, 14 July 2011

Page 16: Java Dating - JSR 310 Lightning Talk

Contact• James Gough

[email protected]

• Twitter: goughjam

163

Thursday, 14 July 2011