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

## superwaba.ext.xplat.util.datergf
Class DateFormat

    java.lang.Object
      |
      +--superwaba.ext.xplat.util.datergf.DateFormat

public class DateFormat
extends Object

This class helps to format Date objects in strings, using various renderings.

     Temporary dev-infos:

        version  date            remark

        0.9.2    2001-03-20      - adding option "S" for displaying milliseconds

                 2001-04-02      - introduced variant "JAVA" and "WABA"

        0.9.3    2001-04-27      - "JAVA" variant now stores localized formatting strings
                                   for use for packages like BSF4Rexx

`DateFormat` is an implementation of formatting dates and times using either the Java-style or the Unix-style keys (strfmt, escaping formatting keys with a percent sign "%"). The formatting keys consist of letters, which may be repeated one or more times in order to indicate different renderings.

This class has a Waba and a Java version, due to the following methods, which are implemented depending on the runtime environment:

Implemented? |  |
Java | Waba | Method name | Short Description
yes | yes | public static void localize() | Sets formatting options of `Date` and `Time` to the local/default Locale settings.
no | yes | public static void localize(java.util.Locale loc) | Sets formatting options of `Date` and `Time` according to the settings of the Locale available to the Java runtime environment.
no | yes | protected static int findFirstDigit(String str) | Helper method for the Java runtime environment version.
no | yes | protected static int toInt(String str, int start, int length) | Helper method for the Java runtime environment version.

This version was created with Waba (e.g. http://www.SuperWaba.org) family of Java-compatible mobile systems (PDAs, Handies, etc.) in mind. Hence this package does not use threads or exceptions. The Waba version does not employ the datatypes long and double, which may not be available on other Java Virtual machine compatible implementations for small devices like PDAs.

This particular class was derived from Toby Thurston's Rexx program named "makedate.cmd", which is part of his great cal-package (a calendar package for the freely available x2-editors (by Blair W. Thompson) available for practically all operating systems (even with Java language support) and having Rexx as its macro language.

Examples:

       Date d=new Date(2033, 9, 22);             // yields: '2033-09-22'

       String  info1=format("EEEE, yy-MMM-dd!",   d);  // yields: "Thursday, 33-Sep-22!"
       String  info2=format("%A, %y-%b-%d!",      d);  // yields: "Thursday, 33-Sep-22!"

       String  info3=format("'days so far: 'DDD", d);  // yields: "days so far: 265"
       String  info4=format("'days to go:  'ggg", d);  // yields: "days to go:  100"

Field Summary
`protected static char[]` | `options` Supported format character keys in argument `fmt` of method `format(String fmt, Object obj)`.
`static String[]` | `romanL` Array of lowercase roman number strings (1 through 12).
`static String[]` | `romanU` Array of uppercase roman number strings (1 through 12).

Constructor Summary
`DateFormat()`

Method Summary
`static String` | `format(String fmt, Object obj)` Creates a string according to a format pattern, using objects of type DateTimeRGF, DateRGF or TimeRGF.
`protected static int` | `pos(char needle, String string, int start)` Returns the 0-based position of `needle` in `string`, starting the search at the indicated 0-based `start` position, or `-1`, if not found.
`protected static int` | `verify(char needle, char[] reference)` Verifies that `needle` is in character array of `reference`.
`static void` | `W_localize()` Sets the national language characteristics of the Date/Time/RGF package.

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

Field Detail

### romanL

    public static final String[] romanL

  Array of lowercase roman number strings (1 through 12).

### romanU

    public static final String[] romanU

  Array of uppercase roman number strings (1 through 12).

### options

    protected static char[] options

  Supported format character keys in argument `fmt` of method `format(String fmt, Object obj)`. Characters: `"yMdhHmsSEeoRrDgwakK"`.

Constructor Detail

### DateFormat

    public DateFormat()

Method Detail

### format

    public static String format(String fmt,
                                Object obj)

  Creates a string according to a format pattern, using objects of type DateTimeRGF, DateRGF or TimeRGF.

  Text enclosed within single or double quotes is unchanged (the enclosing quotes are removed). If one needs to use the quotes themselves, either use the other quote to enclose them or escape the quote by doubling (i.e. use another quote to immediately follow the first one) it. (It is also possible to escape the percentage sign outside of quotes by doubling it.)

  The following table lists the available keys and explains the formatting induced by it. The symbols where picked from Java's SimpleDateFormat().

  Keys |
  Java | Unix | Formatting
  d | %e | day of month
  dd | %d | day of month with leading 0
  e | %w | day of week (Monday=1 ... Sunday=7)
  o | --- | ordinal number of day of week, relative to `Date.weekStart`; e.g. if weeks start with Sunday, then Sunday=1 and Saturday=7; if weeks start with Monday, then Monday=1 and Sunday=7. Note: extension of this package!
  E | %a | first three letters of the dayname (abbreviation)
  EEEE | %A | full name of the day
  M | --- | number of the month
  MM | %m | number of the month with leading 0
  MMM | %b | first three letters of the monthname
  MMMM | %B | full name of the month
  r | --- | number of the month as a lowercase Roman number Note: extension of this package!
  R | --- | number of the month as an uppercase Roman number Note: extension of this package!
  w | %W | week of the year (according to ISO rules)
  ww | --- | week of the year (according to ISO rules) with leading 0
  y | --- | year
  yy | %y | the last two digits in year, leading 0
  yyy | --- | year with as many digits as needed
  yyyy | %Y | year with four digits, leading 0
  D | --- | day of the year (Julian date), no leading 0
  DD | --- | day of the year (Julian date), at least two digits (leading 0)
  DDD | %j | day of the year (Julian date), exactly three digits (leading 0)
  g | --- | days to end of year, no leading 0 Note: extension of this package!
  gg | --- | days to end of year, at least two digits (leading 0) Note: extension of this package!
  ggg | --- | days to end of year, exactly three digits (leading 0) Note: extension of this package!
  H | --- | hour (range: 0-23)
  HH | --- | hour, two digits (leading 0, range: 0-23)
  k | --- | hour (range: 1-24)
  kk | --- | hour, two digits (leading 0, range: 1-24)
  K | --- | hour in am/pm (range: 0-11)
  KK | --- | hour in am/pm, two digits (leading 0, range: 0-11)
  h | --- | hour in am/pm (range: 1-12)
  hh | --- | hour in am/pm, two digits (leading 0, range: 1-12)
  m | --- | minute
  mm | --- | minute, two digits (leading 0)
  s | --- | second
  ss | --- | second, two digits (leading 0)
  S | --- | millisecond
  SS | --- | millisecond, at least two digits (leading 0)
  SSS | --- | millisecond, exactly three digits (leading 0)
  a | --- | am/pm marker

  Examples:

          DateTime dt=new DateTime(2033, 9, 22, 12, 6, 59); // yields: '2033-09-22 12:06:59'

          String  info1=format("EEEE, d. MMMM yyyy, hh:mm a 'o''clock'", dt);
                                 // info1: "Thursday, 22. September 2033, 12:06 pm o'clock"

          String  info2=format("EEEE, yy-MMM-dd!",   dt); // yields: "Thursday, 33-Sep-22!"
          String  info3=format("%A, %y-%b-%d!",      dt); // yields: "Thursday, 33-Sep-22!"

          String  info4=format("D/ggg", dt);              // yields: "265/100"

          String  info5=format("'week #' w", dt);         // yields: "week # 38"

          String  info6=format("'day of week:' e", dt);   // yields: "day of week: 4"
          String  info7=format("'dayname:    ' EEEE", dt);// yields: "dayname: Thursday"
          String  info8=format("'ordinal day:' o", dt);   // yields: "ordinal day: 5", if
                                                          //          Date.weekStart=7

          String  info9=format("d. R. yyyy", dt);         // yields: "22. IX. 2033"

  Parameters:
    `fmt` - the string containing formatting codes.
    `obj` - an instance of DateTimeRGF, DateRGF or TimeRGF.
  Returns:
    a String containing formatted Date data.

### verify

    protected static int verify(char needle,
                                char[] reference)

  Verifies that `needle` is in character array of `reference`. Modelled after Rexx' VERIFY() function.
  Parameters:
    `needle` - character to check.
    `reference` - array of characters to verify with.
  Returns:
    0-based index into `reference` having the same value as needle, or `-1` if not found.

### pos

    protected static int pos(char needle,
                             String string,
                             int start)

  Returns the 0-based position of `needle` in `string`, starting the search at the indicated 0-based `start` position, or `-1`, if not found. This is modelled after Rexx' POS() function.

### W_localize

    public static void W_localize()

  Sets the national language characteristics of the Date/Time/RGF package. This affects the Strings of the daynames, monthnames and am/pm Strings as well as the date and time separators, the default order of the date fields, the day which starts a week, the date the Gregorian calendar took effect.

  This method assumes the class waba.sys.Settings to be available (introduced by Guich with SuperWaba), if the version is `>100`, i.e. any version after the introduction of Waba 1.0.

  The following settings are affected by this method:

  - `Date.dateOrder`,
  - `Date.dateSeparator`,
  - `Date.weekStart`,
  - `Time.is24Hour`,
  - `Time.timeSeparator`.

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