short history of time - confitura 2013
TRANSCRIPT
![Page 2: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/2.jpg)
Tomasz Nurkiewicz |
6+ years with JavaScala, JavaScript, Clojure...Backend, data analysis and visualization
| Used to be active on Third time speaker on Javarsovia/ConfituraWorking in Oslo ( )
nurkiewicz.blogspot.com
[email protected] @tnurkiewicz
scala.net.pl github.com/nurkiewiczStackOverflow
we are hiring!
![Page 3: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/3.jpg)
Bad day at Microsoft
blogs.msdn.com/b/windowsazure/archive/2012/03/09/summaryofwindowsazureservicedisruptiononfeb29th2012.aspx
![Page 4: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/4.jpg)
Program result?Java:
C#:
Calendar cal = new GregorianCalendar(2012, FEBRUARY, 29, 15, 0);cal.add(YEAR, 1);System.out.println(cal.getTime());
DateTime cal = new DateTime(2012, 2, 29, 15, 0, 0).AddYears(1);Console.WriteLine(cal);
![Page 5: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/5.jpg)
February 28th, 2013, 15:00February 29th, 2013, 15:00March 1st, 2013, 00:00March 1st, 2013, 15:00IllegalArgumentException
![Page 6: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/6.jpg)
True story“[...] in accordance with Terms and Conditions [...] interest is paidfor actual number of days funds were on account [...] however it is
assumed that year consists of 365 days.Year 2012 has 366 days, thus
interest is not paid for 29th of February.Yours faithfully, [some] Bank”
samcik.blox.pl/2012/03/DzienktoregoniemaSprawdzcobankwykreslil.html
![Page 7: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/7.jpg)
Bad second for Linux
www.greenprophet.com/2012/07/leapsecondbugconsumesmegawattsofelectricity/
![Page 9: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/9.jpg)
Inne błędyProblem of year 2000 (Y2K)Problem of year 2011 (Taiwan)Problem of year 2038 (Integer.MAX_VALUE)Problem of year 2042 (IBM S/370)Problem of year 2107 (MSDOS FAT)Problem of September 9th, '99 (9/9/99)
en.wikipedia.org/wiki/Time_formatting_and_storage_bugs
![Page 10: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/10.jpg)
Understand the domain...of every problem
![Page 11: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/11.jpg)
Date representation
www.edali.org/persistenceofmemory.jsp
![Page 12: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/12.jpg)
Seconds since arbitrary moment in timeCalendar system
![Page 13: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/13.jpg)
Time axis
![Page 14: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/14.jpg)
Time "0"?Date Used in
0. January 0 MATLAB
1. January 0 Symbian, Turbo DB
1. January 1 Microsoft .NET, Go
1. January 1601 NTFS, COBOL, Win32/Win64
1. January 1753 Microsoft SQL Server
31. December 1840 MUMPS
17. November 1858 VMS, United States Naval Observatory, DVB SI, astronomia
30. December 1899 Microsoft COM DATE, Object Pascal
0. January 1900 Microsoft Excel, Lotus 123
1. January 1900 NTP, IBM CICS, Mathematica, RISC OS, Common Lisp
1. January 1904 LabVIEW, Mac OS 9, Palm OS, MP4
1. January 1950 SEGA Dreamcast
Date Used in
1. January 1960 SPlus, SAS
31. December 1967 Pick OS
1. January 1970 Linux, Mac OS X, C, Java, JavaScript,
Perl, PHP, Python, Tcl, ActionScript
1. January 1978 AmigaOS
1. January 1980 DOS, OS/2, FAT16 I FAT32, VOS
6. January 1980 Qualcomm BREW, GPS
1. January 1981 Acorn NetFS
1. January 1984 CiA® CANopen®
22. August 1999 Satelita Galileo
1. January 2000 PostgreSQL, AppleSingle, AppleDouble
1. January 2001 Apple Cocoa
en.wikipedia.org/wiki/Epoch_date
![Page 15: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/15.jpg)
java.util.Date:
vs.:
en.wikipedia.org/wiki/Calendar_date“A date in a calendar is a reference to a particular day
represented within a calendar system. [...] A particular day maybe represented by a different date in another calendar”
docs.oracle.com/javase/7/docs/api/java/util/Date.html“The class Date represents a specific instant in time, with
millisecond precision.”
![Page 16: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/16.jpg)
Time zonesjava.util.Timezone
![Page 17: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/17.jpg)
Time difference between Warsaw and Sydney?
www.travel.com.hk/region/timezone.htm
![Page 18: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/18.jpg)
DST (Daylight saving time)
en.wikipedia.org/wiki/Daylight_saving_time
![Page 19: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/19.jpg)
Daylight saving time
Winter → Summer Summer → Winteren.wikipedia.org/wiki/Daylight_saving_time
![Page 21: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/21.jpg)
Representation
WRONG!final TimeZone tz = TimeZone.getTimeZone("Europe/Warsaw");
TimeZone.getTimeZone("GMT+01:00");
TimeZone.getTimeZone("Europe/warsaw");
![Page 22: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/22.jpg)
Calendar datejava.util.Calendar
![Page 23: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/23.jpg)
Leap years - WRONG! def leapYear(year: Int): Boolean = year % 4 == 0
![Page 24: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/24.jpg)
Leap years - poor def leapYear(year: Int): Boolean = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)
![Page 25: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/25.jpg)
Leap years def leapYear(year: Int): Boolean = new GregorianCalendar(year, JANUARY, 1). getActualMaximum(DAY_OF_YEAR) > 365
![Page 26: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/26.jpg)
PuzzleCalendar c = Calendar.getInstance();
System.out.println(c.get(Calendar.YEAR));
![Page 27: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/27.jpg)
We have (Gregorian) year 2013
Meanwhile in Thailand...
...and in Japan...
$ java ...2013
$ java -Duser.country=TH -Duser.language=th ...2556
$ java -Duser.country=JP -Duser.language=ja -Duser.variant=JP ...25
![Page 28: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/28.jpg)
Better:
Even better:
Just in case...
Calendar c = new GregorianCalendar();
Calendar c = new GregorianCalendar(timeZone);
Calendar c = new GregorianCalendar(timeZone, locale);
![Page 29: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/29.jpg)
Date vs. Calendar?"...after some another event""...within 10 seconds""...within an hour""...within 24 hours""...within one day""...in 2013""...after 17:00""...on Friday"
![Page 30: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/30.jpg)
Practice
![Page 31: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/31.jpg)
Joda Timefinal DateTime yearLater = new DateTime(2012, 2, 29, 15, 0).plusYears(1);
jodatime.sourceforge.net
![Page 32: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/32.jpg)
Joda Time and JAX-WSimport org.joda.time.DateTime;import javax.xml.bind.DatatypeConverter;
public class XsdJodaTimeConverter { public static DateTime unmarshal(String dateTime) { final long millis = DatatypeConverter. parseDate(dateTime). getTimeInMillis(); return new DateTime(millis); }
public static String marshal(DateTime calendar) { return DatatypeConverter.printDate( calendar.toGregorianCalendar() ); }}
![Page 33: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/33.jpg)
JAX-WS: .xjb file<bindings version="1.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <globalBindings> <javaType xmlType="xs:dateTime" name="org.joda.time.DateTime" parseMethod="XsdJodaTimeConverter.unmarshal" printMethod="XsdJodaTimeConverter.marshal"/> </globalBindings></bindings>
![Page 34: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/34.jpg)
Joda Time and JPA 2.1import org.joda.time.Instant;import javax.persistence.AttributeConverter;import javax.persistence.Converter;import java.util.Date;
@Converter(autoApply = true)public class JodaTimeConverter implements AttributeConverter<Instant, Date> {
@Override public Date convertToDatabaseColumn(Instant attr) { return attr != null? attr.toDate(): null; }
@Override public Instant convertToEntityAttribute(Date dbData) { return dbData != null? new Instant(dbData): null; }}
![Page 35: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/35.jpg)
Testing - toolsControlled time source ( )"Exotic" default time zoneDon't sleep! (Thread.sleep()), ScalaCheck
fake system clock
Awaitility
![Page 36: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/36.jpg)
Testing - edge casesBeginning/end of month/yearWeekends29th of FebruaryTime zones, DST
![Page 37: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/37.jpg)
ScalaCheck and ScalaTest
Negative result
implicit override val generatorDrivenConfig = PropertyCheckConfig(minSuccessful = 10000, workers = 4)
test("any date +1 year and -1 year should yield same date back") { check { random: Date => { val plusMinusYear = new GregorianCalendar plusMinusYear.setTime(random) plusMinusYear.add(YEAR, 1) plusMinusYear.add(YEAR, -1) random == plusMinusYear.getTime } }}
Falsified after 2665 passed tests: arg0 = Mon Feb 29 03:21:22 CET 73843340
![Page 38: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/38.jpg)
Events in the future, , ...
QuartzJMS
Activiti jBPM
![Page 39: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/39.jpg)
Quartz schedulernewTrigger() .startAt(futureDate(1, YEAR)) .build();
quartzscheduler.org/documentation/quartz2.1.x/tutorials/tutoriallesson05
![Page 40: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/40.jpg)
JMS with delayMessageProducer producer = session.createProducer(destination);TextMessage message = session.createTextMessage("...hello, delayed!");message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, oneYearMillis);producer.send(message);
http://activemq.apache.org/delayandschedulemessagedelivery.html
![Page 41: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/41.jpg)
Bonus / Computus(defn easter [year] (let [ a (mod year 19) b (Math/floor (/ year 100)) c (mod year 100) d (Math/floor (/ b 4)) e (mod b 4) f (Math/floor (/ (+ b 8) 25)) g (Math/floor (/ (inc (- b f)) 3)) h (mod (+ (- (+ (* 19 a) b) d g) 15) 30) i (Math/floor (/ c 4)) k (mod c 4) L (mod (- (+ 32 (* 2 e) (* 2 i)) h k) 7) m (Math/floor (/ (+ a (* 11 h) (* 22 L)) 451)) n (- (+ h L 114) (* 7 m)) month (dec (Math/floor (/ n 31))) day (inc (mod n 31))] (java.util.GregorianCalendar. year month day)))
en.wikipedia.org/wiki/Computus
![Page 42: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/42.jpg)
Bugs, more bugs...1. "Due to the lack of [time] synchronization [...] a car bomb went off [...] one hour earlier than
expected" ( )2. "F22 Raptors [...] experienced multiple computer crashes coincident with their crossing of
[...] the International Date Line" ( )3. "Damage to a German steel facility occurred during a DST transition" (
)4.
5. 6. Unjustified fraud accusation ( [37])7. Catalog of few hundred bugs, up to year 2000 (!) (
)
catless.ncl.ac.uk/Risks/20.58.html#subj12
en.wikipedia.org/wiki/List_of_software_bugs
en.wikipedia.org/wiki/Daylight_Savings_Timewww.wired.com/wiredenterprise/2012/07/leapsecondbugwreakshavocwithjavalinuxwww.theregister.co.uk/2012/07/02/leap_second_crashes_airlines
www.cs.tau.ac.il/~nachumd/horror.html
www.csl.sri.com/users/neumann/cal.html
![Page 43: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/43.jpg)
Interesting and useful1. everything about time2. UNIX time3. foundation for this presentation4. definitions of TAI, UT, UTC...5. Samoa and Tokelau skip a day for dateline
change
www.timeanddate.comwww.epochconverter.comwww.odi.ch/prog/design/datetime.phptycho.usno.navy.mil/systime.htmlwww.bbc.co.uk/news/worldasia16351377
![Page 44: Short history of time - Confitura 2013](https://reader034.vdocument.in/reader034/viewer/2022042700/554f8427b4c905d25b8b4bb0/html5/thumbnails/44.jpg)
Thank you for your... time!
Twitter: [email protected]
@tnurkiewicz
nurkiewicz.github.io/talks/confitura2013