org.jfree.formula.util

Class HSSFDateUtil

public class HSSFDateUtil extends Object

Contains methods for dealing with Excel dates.
Modified by Cedric Pronzato

Author: Michael Harhen Glen Stampoultzis (glens at apache.org) Dan Sherman (dsherman at isisph.com) Hack Kampbjorn (hak at 2mba.dk)

Method Summary
static doublegetExcelDate(Date date)
Given a Date, converts it into a double representing its internal Excel representation, which is the number of days since 1/1/1900.
static DategetJavaDate(double date)
Given a excel date, converts it into a Date.
static DategetJavaDate(double date, boolean use1904windowing)
Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.util.Date.
static booleanisInternalDateFormat(int format)
given a format ID this will check whether the format represents an internal date format or not.
static booleanisValidExcelDate(double value)
Given a double, checks if it is a valid Excel date.

Method Detail

getExcelDate

public static double getExcelDate(Date date)
Given a Date, converts it into a double representing its internal Excel representation, which is the number of days since 1/1/1900. Fractional days represent hours, minutes, and seconds.

Parameters: date the Date

Returns: Excel representation of Date (-1 if error - test for error by checking for less than 0.1)

getJavaDate

public static Date getJavaDate(double date)
Given a excel date, converts it into a Date. Assumes 1900 date windowing.

Parameters: date the Excel Date

Returns: Java representation of a date (null if error)

See Also: HSSFDateUtil

getJavaDate

public static Date getJavaDate(double date, boolean use1904windowing)
Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.util.Date. NOTE: If the default TimeZone in Java uses Daylight Saving Time then the conversion back to an Excel date may not give the same value, that is the comparison excelDate == getExcelDate(getJavaDate(excelDate,false)) is not always true. For example if default timezone is Europe/Copenhagen, on 2004-03-28 the minute after 01:59 CET is 03:00 CEST, if the excel date represents a time between 02:00 and 03:00 then it is converted to past 03:00 summer time

Parameters: date The Excel date. use1904windowing true if date uses 1904 windowing, or false if using 1900 date windowing.

Returns: Java representation of the date, or null if date is not a valid Excel date

See Also: java.util.TimeZone

isInternalDateFormat

public static boolean isInternalDateFormat(int format)
given a format ID this will check whether the format represents an internal date format or not.

isValidExcelDate

public static boolean isValidExcelDate(double value)
Given a double, checks if it is a valid Excel date.

Parameters: value the double value

Returns: true if valid