
org.nerd4j.time.UnixTimeInterval Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nerd4j-core Show documentation
Show all versions of nerd4j-core Show documentation
Basic beans and utilities.
/*
* #%L
* Nerd4j Core
* %%
* Copyright (C) 2011 - 2013 Nerd4j
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package org.nerd4j.time;
import java.util.Date;
import org.nerd4j.lang.ComparableInterval;
/**
* Represent a time interval into Unix Time range definition.
*
*
* Unix dates are defined between 01/01/1970 00:00:00 UTC and
* 19/01/2038 03:14:07 UTC.
*
*
*
* Every period must have starting and ending dates; if missing (as in case of
* non ending periods) the following can be used:
*
* - no start: {@link #BEGIN_OF_UNIXTIME}
* - no end: {@link #END_OF_UNIXTIME}
*
*
*
* @author Nerd4j Team
*/
public class UnixTimeInterval extends ComparableInterval
{
/** Default Serial Version UID. */
private static final long serialVersionUID = 1L;
/** Unix Time (32bit) begin date: 01/01/1970 00:00:00 UTC. */
public static final Date BEGIN_OF_UNIXTIME = new Date( 0L );
/** Unix Time (32bit) end date: 19/01/2038 03:14:07 UTC. */
public static final Date END_OF_UNIXTIME = new Date( Integer.MAX_VALUE * 1000L );
/** Complete standard Unix Time interval. */
private static final UnixTimeInterval UNIX_TIME_INTERVAL = new UnixTimeInterval();
/**
* Creates a new {@link UnixTimeInterval} without begin and end dates.
*
* Begin and end dates will be set to {@link #BEGIN_OF_UNIXTIME} and
* {@link #END_OF_UNIXTIME} accordingly.
*
*/
protected UnixTimeInterval()
{
super( BEGIN_OF_UNIXTIME, END_OF_UNIXTIME );
}
/**
* Creates a new {@link UnixTimeInterval} virtually without end.
*
*
* End date will be set to {@link #END_OF_UNIXTIME}.
*
*
* @param begin interval begin date.
*
* @throws NullPointerException
* if begin parameter is null
* @throws IllegalArgumentException
* if begin is before {@link #BEGIN_OF_UNIXTIME}
* @throws IllegalArgumentException
* if begin isn't before {@link #END_OF_UNIXTIME}
*/
public UnixTimeInterval( Date begin )
{
this( begin, END_OF_UNIXTIME );
}
/**
* Creates a completely defined new {@link UnixTimeInterval}.
*
* @param begin interval begin date.
* @param end interval end date.
*
* @throws NullPointerException
* if al leas one parameter is null
* @throws IllegalArgumentException
* if begin isn't before end.
* @throws IllegalArgumentException
* if begin is before {@link #BEGIN_OF_UNIXTIME}
* @throws IllegalArgumentException
* if begin is after {@link #END_OF_UNIXTIME}
*/
public UnixTimeInterval( Date begin, Date end )
{
super( begin, end );
if ( begin.before( BEGIN_OF_UNIXTIME ) )
throw new IllegalArgumentException( "The begin date is not in the unix time range" );
if ( end.after( END_OF_UNIXTIME ) )
throw new IllegalArgumentException( "The end date is not in the unix time range" );
}
/**
* Returns the complete standard Unix Time interval.
*
* @return Unix Time definition interval
*/
public static UnixTimeInterval getUnixTimeInterval()
{
return UNIX_TIME_INTERVAL;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy