alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (key_interval.xml)

This example Java source code file (key_interval.xml) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

api, chronology, colebourne, datetime, instead, interval, intervals, iso-8859-1, joda-time, period, the, there

The key_interval.xml Java example source code

<?xml version="1.0" encoding="ISO-8859-1"?>

<document>

 <properties>
  <title>Java date and time API - Interval
  <author>Stephen Colebourne
 </properties>

 <body>

<section name="Interval">

<p>
An <i>interval in Joda-Time represents an interval of time from one millisecond
<a href="key_instant.html">instant to another instant.
Both instants are fully specified instants in the datetime continuum, complete with time zone.
</p>
<p>
Intervals are implemented as <i>half-open, which is to say that the start instant is
inclusive but the end instant is exclusive.
The end is always greater than or equal to the start.
The interval is also restricted to just one <a href="key_chronology.html">chronology and time zone.
</p>
<p>
Methods exist on intervals to obtain the start and end instants plus the chronology and time zone.
There are also methods to obtain the <a href="key_duration.html">duration and
<a href="key_period.html">period of the interval.
</p>
<p>
You cannot compare intervals for order (ie. they do not implement <code>Comparable.
If you want to compare the length of intervals you must obtain the duration of each and compare those.
</p>

</section>

<section name="Using Intervals in Joda-Time">
<p>
Within Joda-Time an interval is represented by the
<a href="apidocs/org/joda/time/ReadableInterval.html">ReadableInterval interface.
There are two implementations of the interface provided:
<ul>
<li>Interval - An immutable implementation
<li>MutableInterval - A mutable implementation
</ul>
We recommend the immutable implementation for general usage.
</p>
<p>
The code can be used in various ways:
<source>
// interval from start to end
DateTime start = new DateTime(2004, 12, 25, 0, 0, 0, 0);
DateTime end = new DateTime(2005, 1, 1, 0, 0, 0, 0);
Interval interval = new Interval(start, end);
</source>
Accessing other objects is easy:
<source>
Interval interval = ...
DateTime start = interval.getStart();
DateTime end = interval.getEnd();
Chronology chrono = interval.getChronology();
Duration duration = interval.toDuration();
Period period = interval.toPeriod();
</source>
</p>
<p>
Note that the interface <code>ReadableInterval should not be used like the collections API.
The interface only contains the core subset of the operations.
Instead, you should usually refer directly to the implementation classes in your APIs.
</p>

<subsection name="Nulls">
<p>
Joda-Time defines a null interval as a zero length interval from now to now.
Thus, when a method is defined as taking a <code>ReadableInterval, passing null in
will be the same as passing in a zero length interval at the current time.
</p>
</subsection>

</section>

</body>
</document>

Other Java examples (source code examples)

Here is a short list of links related to this Java key_interval.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.