gecko-dev/grendel/docs/calypso/util/NetworkDate.html

356 lines
14 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Sun Aug 01 23:07:08 MDT 1999 -->
<TITLE>
: Class NetworkDate
</TITLE>
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
</HEAD>
<BODY BGCOLOR="white">
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_top"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" ID="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT ID="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="package-summary.html"><FONT ID="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" ID="NavBarCell1Rev"> &nbsp;<FONT ID="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="package-tree.html"><FONT ID="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT ID="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../index-all.html"><FONT ID="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../help-doc.html"><FONT ID="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" ID="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../calypso/util/MemoryMonitor.html"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../calypso/util/NullEnumeration.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" ID="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="NetworkDate.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" ID="NavBarCell3"><FONT SIZE="-2">
SUMMARY: &nbsp;INNER&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" ID="NavBarCell3"><FONT SIZE="-2">
DETAIL: &nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
calypso.util</FONT>
<BR>
Class NetworkDate</H2>
<PRE>
java.lang.Object
|
+--<B>calypso.util.NetworkDate</B>
</PRE>
<HR>
<DL>
<DT>public class <B>NetworkDate</B><DT>extends java.lang.Object</DL>
<P>
Parses a date out of a string of bytes. Call it like this:
<P><UL>
<TT>ByteBuf bytes = </TT>...<TT> ;</TT><BR>
<TT>Date date = NetworkDate.parseDate(bytes);</TT>
</UL>
<P> Note that it operates on bytes, not chars, since network
dates are always ASCII.
<P> Why would you want to use this instead of
<TT>java.text.DateFormat.parse()</TT>? Because this algorithm has been
tested in the field against real-world message headers for several
years (the C code hadn't changed substantively since Netscape 2.0.)
(There had been DST-related problems, but the tokenizer/parser was
always sound.)
<P>
<DL>
<DT><B>See Also: </B><DD><CODE>Date</CODE>,
<CODE>Calendar</CODE>,
<CODE>DateFormat</CODE></DL>
<HR>
<P>
<!-- ======== INNER CLASS SUMMARY ======== -->
<!-- =========== FIELD SUMMARY =========== -->
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" ID="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.util.Date</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../calypso/util/NetworkDate.html#parseDate(calypso.util.ByteBuf)">parseDate</A></B>(<A HREF="../../calypso/util/ByteBuf.html">ByteBuf</A>&nbsp;string)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The same, but assumes GMT is the default timezone.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.util.Date</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../calypso/util/NetworkDate.html#parseDate(calypso.util.ByteBuf, boolean)">parseDate</A></B>(<A HREF="../../calypso/util/ByteBuf.html">ByteBuf</A>&nbsp;string,
boolean&nbsp;default_to_gmt)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Like parseLong(), but returns a new Date object instead.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;long</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../calypso/util/NetworkDate.html#parseLong(byte[], int, int, boolean)">parseLong</A></B>(byte[]&nbsp;string,
int&nbsp;start,
int&nbsp;end,
boolean&nbsp;default_to_gmt)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The same, but takes a byte array and a region within it, instead
of a ByteBuf.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;long</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../calypso/util/NetworkDate.html#parseLong(calypso.util.ByteBuf)">parseLong</A></B>(<A HREF="../../calypso/util/ByteBuf.html">ByteBuf</A>&nbsp;string)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The same, but assumes GMT is the default timezone.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;long</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../calypso/util/NetworkDate.html#parseLong(calypso.util.ByteBuf, boolean)">parseLong</A></B>(<A HREF="../../calypso/util/ByteBuf.html">ByteBuf</A>&nbsp;buf,
boolean&nbsp;default_to_gmt)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This parses a time/date string into a Time object.</TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;long</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../calypso/util/NetworkDate.html#UTC(int, int, int, int, int, int)">UTC</A></B>(int&nbsp;year,
int&nbsp;month,
int&nbsp;date,
int&nbsp;hour,
int&nbsp;min,
int&nbsp;sec)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Composes the given date into a number suitable for passing to
<TT>new&nbsp;Date(n)</TT>.</TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#EEEEFF" ID="TableSubHeadingColor">
<TD><B>Methods inherited from class java.lang.Object</B></TD>
</TR>
<TR BGCOLOR="white" ID="TableRowColor">
<TD><CODE>clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait</CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>
<!-- ============ FIELD DETAIL =========== -->
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" ID="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Method Detail</B></FONT></TD>
</TR>
</TABLE>
<A NAME="parseLong(calypso.util.ByteBuf, boolean)"><!-- --></A><H3>
parseLong</H3>
<PRE>
public static long <B>parseLong</B>(<A HREF="../../calypso/util/ByteBuf.html">ByteBuf</A>&nbsp;buf,
boolean&nbsp;default_to_gmt)</PRE>
<DL>
<DD>This parses a time/date string into a Time object.
If it can't be parsed, -1 is returned.
<P>Many formats are handled, including:
<P><UL>
<LI> <TT> 14 Apr 89 03:20:12 </TT>
<LI> <TT> 14 Apr 89 03:20 GMT </TT>
<LI> <TT> Fri, 17 Mar 89 4:01:33 </TT>
<LI> <TT> Fri, 17 Mar 89 4:01 GMT </TT>
<LI> <TT> Mon Jan 16 16:12 PDT 1989 </TT>
<LI> <TT> Mon Jan 16 16:12 +0130 1989 </TT>
<LI> <TT> 6 May 1992 16:41-JST (Wednesday) </TT>
<LI> <TT> 22-AUG-1993 10:59:12.82 </TT>
<LI> <TT> 22-AUG-1993 10:59pm </TT>
<LI> <TT> 22-AUG-1993 12:59am </TT>
<LI> <TT> 22-AUG-1993 12:59 PM </TT>
<LI> <TT> Friday, August 04, 1995 3:54 PM </TT>
<LI> <TT> 06/21/95 04:24:34 PM </TT>
<LI> <TT> 20/06/95 21:07 </TT>
<LI> <TT> 95-06-08 19:32:48 EDT </TT>
</UL>
<P> But note that <TT>6/5/95</TT> is ambiguous, since it's not obvious
which is the day and which is the month. (<TT>6/13/95</TT> is not
ambiguous, however.)<DD><DL>
<DT><B>Parameters:</B><DD><CODE>buf</CODE> - The bytes to parse. This assumes the input to be
a sequence of 8-bit ASCII characters. High-bit
characters are handled; 16-bit Unicode characters
are not.<DD><CODE>default_to_gmt</CODE> - If the input string doesn't contain a description
of the timezone, then this argument determines whether the string is
interpreted relative to the local time zone (false) or to GMT (true).
The correct value to pass in for this argument depends on what standard
specified the time string which you are parsing; for RFC822 dates, this
argument should be true.<DT><B>Returns:</B><DD>Microseconds since Jan 1, 1900, GMT.
You can pass this to <TT>new&nbsp;Date(long)</TT>.
Returns -1 if the string is unparsable
(no other negative value will ever be returned;
dates before the Epoch are not handled.)</DL>
</DD>
</DL>
<HR>
<A NAME="parseLong(byte[], int, int, boolean)"><!-- --></A><H3>
parseLong</H3>
<PRE>
public static long <B>parseLong</B>(byte[]&nbsp;string,
int&nbsp;start,
int&nbsp;end,
boolean&nbsp;default_to_gmt)</PRE>
<DL>
<DD>The same, but takes a byte array and a region within it, instead
of a ByteBuf.</DL>
<HR>
<A NAME="parseLong(calypso.util.ByteBuf)"><!-- --></A><H3>
parseLong</H3>
<PRE>
public static long <B>parseLong</B>(<A HREF="../../calypso/util/ByteBuf.html">ByteBuf</A>&nbsp;string)</PRE>
<DL>
<DD>The same, but assumes GMT is the default timezone.</DL>
<HR>
<A NAME="parseDate(calypso.util.ByteBuf, boolean)"><!-- --></A><H3>
parseDate</H3>
<PRE>
public static java.util.Date <B>parseDate</B>(<A HREF="../../calypso/util/ByteBuf.html">ByteBuf</A>&nbsp;string,
boolean&nbsp;default_to_gmt)</PRE>
<DL>
<DD>Like parseLong(), but returns a new Date object instead.</DL>
<HR>
<A NAME="parseDate(calypso.util.ByteBuf)"><!-- --></A><H3>
parseDate</H3>
<PRE>
public static java.util.Date <B>parseDate</B>(<A HREF="../../calypso/util/ByteBuf.html">ByteBuf</A>&nbsp;string)</PRE>
<DL>
<DD>The same, but assumes GMT is the default timezone.</DL>
<HR>
<A NAME="UTC(int, int, int, int, int, int)"><!-- --></A><H3>
UTC</H3>
<PRE>
public static long <B>UTC</B>(int&nbsp;year,
int&nbsp;month,
int&nbsp;date,
int&nbsp;hour,
int&nbsp;min,
int&nbsp;sec)</PRE>
<DL>
<DD>Composes the given date into a number suitable for passing to
<TT>new&nbsp;Date(n)</TT>. This is the number of milliseconds
past the Epoch.</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" ID="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT ID="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="package-summary.html"><FONT ID="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" ID="NavBarCell1Rev"> &nbsp;<FONT ID="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="package-tree.html"><FONT ID="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT ID="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../index-all.html"><FONT ID="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../help-doc.html"><FONT ID="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" ID="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../calypso/util/MemoryMonitor.html"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../calypso/util/NullEnumeration.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" ID="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="NetworkDate.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" ID="NavBarCell3"><FONT SIZE="-2">
SUMMARY: &nbsp;INNER&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" ID="NavBarCell3"><FONT SIZE="-2">
DETAIL: &nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
</BODY>
</HTML>