You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



All Packages  This Package  Class Hierarchy  Class Search  Index

Class calypso.util.NetworkDate

java.lang.Object
   |
   +----calypso.util.NetworkDate

Parses a date out of a string of bytes. Call it like this:

    ByteBuf bytes = ... ;
    Date date = NetworkDate.parseDate(bytes);

Note that it operates on bytes, not chars, since network dates are always ASCII.

Why would you want to use this instead of java.text.DateFormat.parse()? 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.)

See Also: Date, Calendar, DateFormat


public class  NetworkDate
     extends java.lang.Object
{
          // Fields 36
     private static final int APR;
     private static final int AST;
     private static final int AUG;
     private static final int BST;
     private static final int CDT;
     private static final int CST;
     private static final int DEC;
     private static final int EDT;
     private static final int EET;
     private static final int EST;
     private static final int FEB;
     private static final int FRI;
     private static final int GMT;
     private static final int JAN;
     private static final int JST;
     private static final int JUL;
     private static final int JUN;
     private static final int MAR;
     private static final int MAY;
     private static final int MDT;
     private static final int MET;
     private static final int MON;
     private static final int MST;
     private static final int NOV;
     private static final int NST;
     private static final int OCT;
     private static final int PDT;
     private static final int PST;
     private static final int SAT;
     private static final int SEP;
     private static final int SUN;
     private static final int THU;
     private static final int TUE;
     private static final int UNKNOWN;
     private static final int WED;
     private static final short[] monthOffset;

          // Constructors 1
     private NetworkDate();

          // Methods 7
     public static long UTC(int, int, int, int, int, int);
     private static int localZoneOffset();
     public static Date parseDate(ByteBuf);
     public static Date parseDate(ByteBuf, boolean);
     public static long parseLong(byte[], int, int, boolean);
     public static long parseLong(ByteBuf);
     public static long parseLong(ByteBuf, boolean);
}



Fields


UNKNOWN

   private static final int UNKNOWN


SUN

   private static final int SUN


MON

   private static final int MON


TUE

   private static final int TUE


WED

   private static final int WED


THU

   private static final int THU


FRI

   private static final int FRI


SAT

   private static final int SAT


JAN

   private static final int JAN


FEB

   private static final int FEB


MAR

   private static final int MAR


APR

   private static final int APR


MAY

   private static final int MAY


JUN

   private static final int JUN


JUL

   private static final int JUL


AUG

   private static final int AUG


SEP

   private static final int SEP


OCT

   private static final int OCT


NOV

   private static final int NOV


DEC

   private static final int DEC


PST

   private static final int PST


PDT

   private static final int PDT


MST

   private static final int MST


MDT

   private static final int MDT


CST

   private static final int CST


CDT

   private static final int CDT


EST

   private static final int EST


EDT

   private static final int EDT


AST

   private static final int AST


NST

   private static final int NST


GMT

   private static final int GMT


BST

   private static final int BST


MET

   private static final int MET


EET

   private static final int EET


JST

   private static final int JST


monthOffset

   private static final short[] monthOffset



Constructors


NetworkDate

   private NetworkDate() 



Methods


parseLong

   public static long parseLong(ByteBuf buf, 
                                boolean default_to_gmt) 

This parses a time/date string into a Time object. If it can't be parsed, -1 is returned.

Many formats are handled, including:

  • 14 Apr 89 03:20:12
  • 14 Apr 89 03:20 GMT
  • Fri, 17 Mar 89 4:01:33
  • Fri, 17 Mar 89 4:01 GMT
  • Mon Jan 16 16:12 PDT 1989
  • Mon Jan 16 16:12 +0130 1989
  • 6 May 1992 16:41-JST (Wednesday)
  • 22-AUG-1993 10:59:12.82
  • 22-AUG-1993 10:59pm
  • 22-AUG-1993 12:59am
  • 22-AUG-1993 12:59 PM
  • Friday, August 04, 1995 3:54 PM
  • 06/21/95 04:24:34 PM
  • 20/06/95 21:07
  • 95-06-08 19:32:48 EDT

But note that 6/5/95 is ambiguous, since it's not obvious which is the day and which is the month. (6/13/95 is not ambiguous, however.)

Parameter Description
buf 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.
default_to_gmt 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.

Returns:
Microseconds since Jan 1, 1900, GMT. You can pass this to new Date(long). Returns -1 if the string is unparsable (no other negative value will ever be returned; dates before the Epoch are not handled.)


parseLong

   public static long parseLong(byte[] string, 
                                int start, 
                                int end, 
                                boolean default_to_gmt) 

The same, but takes a byte array and a region within it, instead of a ByteBuf.



parseLong

   public static long parseLong(ByteBuf string) 

The same, but assumes GMT is the default timezone.



parseDate

   public static Date parseDate(ByteBuf string, 
                                boolean default_to_gmt) 

Like parseLong(), but returns a new Date object instead.



parseDate

   public static Date parseDate(ByteBuf string) 

The same, but assumes GMT is the default timezone.



UTC

   public static long UTC(int year, 
                          int month, 
                          int date, 
                          int hour, 
                          int min, 
                          int sec) 

Composes the given date into a number suitable for passing to new Date(n). This is the number of milliseconds past the Epoch.



localZoneOffset

   private static int localZoneOffset() 


All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.4