Java may get time, date upgrade
- By Joab Jackson
- Jun 03, 2008
A number of developers are working on new time and date
interfaces for the Java programming language.
At the JavaOne 2008 Conference last month, Stephen Colebourne,
an architect at Switzerland-based integrator Sita, and Michael
Santos, a senior technical consultant at Summa Technologies,
presented their work on the Java
Specification Request (JSR) 310 ' Date and Time Application
Programming Interface (API).
Although Java has a class to define dates and another class to
define time, both have a number of
shortcomings, the developers said. The new API will allow
developers to work with dates and time with far more flexibility,
The API will offer developers two broad definitions of time: One
is continuous time or machine time, and the other is human
For continuous time, the API will include a way to record an
instant of time, which would be captured as so many units after a
predefined epoch. The base is a single number representing some
point in time, as referenced from some earlier predefined point in
In continuous time, two instances could be used to create an
interval ' or the set of all instances that lie between the
start and end times. The instances could also be used to create a
duration ' namely, the length of time between two events.
"You will be able to build an instance [that records] a number
of seconds or a number of nanoseconds," Santos said. "You will also
be able to compare instances to see if one happens before or after
the other. Or you can check to see if an instant appears within an
The second kind of time the API supports ' human time
' breaks time into a number of recognizable fields, such as
the year, month, hour, minute and second. For human time, the API
will adopt ISO standard 8601.
In this standard, dates are represented in the yyyy-mm-dd
format. Accordingly, June 3, 2008, would be represented as
2008-06-03. The time of day would be represented in the hh:mm:ss
format; thus, 9:15 a.m. Eastern Time would be represented as
09:15:00. ISO 8601 also offers an annotation for specifying the
offset of this time from Universal Coordinated Time.
In addition, JSR 310 will also include features to help resolve
some of the trickier problems programmers face when devising
calculations involving dates and time.
A feature known as a resolver can, when given an incorrect date
(e.g., Feb. 30), adjust it to the correct date (March 1 or March 2
depending on whether it is a leap year). Another feature, called an
adjuster, can calculate a date when given a set of conditions. For
instance, it can allow a program to ask what the last day of any
given month is.
Another feature adjusts the timestamps that might have gotten
botched by Daylight Saving Time rules, which can help parse those
periods of time in which events in two separate hours are recorded
as happening in the same hour due to clocks being set back an
Colebourne said the development team is also planning to make
the API extensible because "there are many ways to manipulate
time." For instance, some organizations pay employees every other
week, while others pay their people twice a month. Making the API
extensible ensures that each organization can manipulate their time
data in ways that are specific to their organizations.
Another example of extensibility is the calendaring system. By
default, the API will use the Gregorian calendar system. However,
other calendars could be entered as separate date classes. Examples
include the Hebrew calendar, the Japanese calendar and historic
calendars such as the Julian calendar.
"If you know the particular calendar system you want to deal
with, then you have a date object that represents just that
particular calendar system," Colebourne said.
A JSR is a proposed specification for extending the Java
programming language. It could be integrated with the current
date/time classes because the keepers of the Java language have no
plans to deprecate those classes. The Java Community Process
program, which manages Java, has made no decision on including JSR
310 in Java 7, the next version of the programming language. The
developers are seeking other volunteers to help further define the
"We want to make sure this JSR works," Colebourne said.
'We can't afford a third broken date-and-time API.'
Joab Jackson is the senior technology editor for Government Computer News.