: Class NetworkDate

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## calypso.util
Class NetworkDate

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

public class NetworkDate
extends java.lang.Object

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`

Method Summary
`static java.util.Date` | `parseDate(ByteBuf string)` The same, but assumes GMT is the default timezone.
`static java.util.Date` | `parseDate(ByteBuf string, boolean default_to_gmt)` Like parseLong(), but returns a new Date object instead.
`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.
`static long` | `parseLong(ByteBuf string)` The same, but assumes GMT is the default timezone.
`static long` | `parseLong(ByteBuf buf, boolean default_to_gmt)` This parses a time/date string into a Time object.
`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)`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### 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.)

  Parameters:
    `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 java.util.Date parseDate(ByteBuf string,
                                           boolean default_to_gmt)

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

### parseDate

    public static java.util.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.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD