14. 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
25. Leap years
def leapYear(year: Int): Boolean =
new GregorianCalendar(year, JANUARY, 1).
getActualMaximum(DAY_OF_YEAR) > 365
26. Puzzle
Calendar c = Calendar.getInstance();
System.out.println(c.get(Calendar.YEAR));
27. 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
28. Better:
Even better:
Just in case...
Calendar c = new GregorianCalendar();
Calendar c = new GregorianCalendar(timeZone);
Calendar c = new GregorianCalendar(timeZone, locale);
31. Joda Time
final DateTime yearLater = new DateTime(2012, 2, 29, 15, 0).plusYears(1);
jodatime.sourceforge.net
32. Joda Time and JAX-WS
import 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()
);
}
}
36. Testing - edge cases
Beginning/end of month/year
Weekends
29th of February
Time zones, DST
37. 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
38. Events in the future
, , ...
Quartz
JMS
Activiti jBPM
41. 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
42. 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_Time
www.wired.com/wiredenterprise/2012/07/leapsecondbugwreakshavocwithjava
linux
www.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
43. Interesting and useful
1. everything about time
2. UNIX time
3. foundation for this presentation
4. definitions of TAI, UT, UTC...
5. Samoa and Tokelau skip a day for dateline
change
www.timeanddate.com
www.epochconverter.com
www.odi.ch/prog/design/datetime.php
tycho.usno.navy.mil/systime.html
www.bbc.co.uk/news/worldasia16351377
44. Thank you for your... time!
Twitter:
nurkiewicz@gmail.com
@tnurkiewicz
nurkiewicz.github.io/talks/confitura2013