|
20080913, rgf | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.oorexx.datergf.DateFormatRGF
This class helps to format DateRGF objects in strings, using various renderings.
DateFormatRGF
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? | |||
Waba | Java | Method name | Short Description |
yes | yes | public static void localize() | Sets formatting options of
DateRGF and
TimeRGF to the local/default Locale
settings.
|
no | yes | public static void localize(java.util.Locale loc) | Sets formatting options of
DateRGF and
TimeRGF 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:
DateRGF d=new DateRGF(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"
------------------------ Apache Version 2.0 license ------------------------- Copyright (C) 2001-2006 Rony G. Flatscher Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- Temporary dev-infos: version date remark 0.92 2001-03-20 - adding option "S" for displaying milliseconds 2001-04-02 - introduced variant "JAVA" and "WABA" 2005-12-28 - added Apache license 2.0, put sources with BSF4Rexx
Field Summary | |
protected static char[] |
options
Supported format character keys in argument fmt of
method
format(String fmt, Object obj) .
|
static java.lang.String[] |
romanL
Array of lowercase roman number strings (1 through 12). |
static java.lang.String[] |
romanU
Array of uppercase roman number strings (1 through 12). |
static java.lang.String |
version
Version string indicating version of this class (majorVersion*100+minorVersion concatenated with a dot and the sorted date of last change. |
Constructor Summary | |
DateFormatRGF()
|
Method Summary | |
protected static int |
findFirstDigit(java.lang.String str)
Searches a String and returns the 0-based index of the first digit character, -1 else. |
static java.lang.String |
format(java.lang.String fmt,
java.lang.Object obj)
Creates a string according to a format pattern, using objects of type DateTimeRGF, DateRGF or TimeRGF. |
static void |
localize()
Sets the national language characteristics of the Date/Time/RGF package. |
static void |
localize(java.util.Locale loc)
Sets the national language characteristics of the Date/Time/RGF package using the Java runtime information. |
protected static int |
pos(char needle,
java.lang.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 |
toInt(java.lang.String str,
int start,
int length)
Calculates the int value from a string built of digit characters only. |
protected static int |
verify(char needle,
char[] reference)
Verifies that needle is in character array of reference .
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static java.lang.String version
public static final java.lang.String[] romanL
public static final java.lang.String[] romanU
protected static char[] options
fmt
of
method
format(String fmt, Object obj)
.
Characters: "yMdhHmsSEeoRrDgwakK"
.
Constructor Detail |
public DateFormatRGF()
Method Detail |
public static java.lang.String format(java.lang.String fmt, java.lang.Object obj)
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
DateRGF.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:
DateTimeRGF dt=new DateTimeRGF(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 // DateRGF.weekStart=7 String info9=format("d. R. yyyy", dt); // yields: "22. IX. 2033"
fmt
- the string containing formatting codes.obj
- an instance of DateTimeRGF,
DateRGF or
TimeRGF.
protected static int verify(char needle, char[] reference)
needle
is in character array of reference
.
Modelled after Rexx' VERIFY() function.
needle
- character to check.reference
- array of characters to verify with.
reference
having the same value as needle,
or -1
if not found.protected static int pos(char needle, java.lang.String string, int start)
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.
public static void localize()
java.util.Locale()
to determine the specific NLS settings of the machine this code
runs at. The work itself is carried out in method
localize(java.util.Locale loc)
.
waba.sys.Settings()
is used. Not implemented as of yet!
public static void localize(java.util.Locale loc)
toString()
methods reflect the new formats.
There is no Waba dependent version of this method!
The following settings are affected by this method:
DateRGF#dateOrder
,
DateRGF#dayNames
(Java runtime only),
DateRGF.dateSeparator
,
DateRGF#monthNames
(Java runtime only),
DateRGF#stGC
(Java runtime only),
DateRGF#weekStart
,
TimeRGF.am_pm_string
,
TimeRGF.is24Hour
,
TimeRGF.timeSeparator
.
format(String fmt, Object obj)
will use
the localized versions of the daynames, monthnames and the am/pm string.
Examples:
DateTimeRGF dt = new DateTimeRGF(2033, 9, 22, 12, 6, 59); String form = "EEEE, yyyy-mmm-dd HH:mm/hh:mm a"; String s1, s2, s3, s4, s5, s6, s7, s8; s1=DateFormatRGF.format(form, dt); // yields: "Thursday, 2033-06-22 12:06/12:06 pm" s2=dt.toString(); // yields: "2033-09-22 12:06:59" localize(java.util.Locale.GERMAN); s3=DateFormatRGF.format(form, dt); // yields: "Donnerstag, 2033-06-22 12:06/12:06 PM" s4=dt.toString(); // yields: "22.09.2033 12:06:59" localize(java.util.Locale.ITALIAN); s5=DateFormatRGF.format(form, dt); // yields: "giovedì, 2033-06-22 12:06/12:06 PM" s6=dt.toString(); // yields: "22/09/2033 12.06.59" localize(java.util.Locale.US); s7=DateFormatRGF.format(form, dt); // yields: "Thursday, 2033-06-22 12:06/12:06 PM" s8=dt.toString(); // yields: "09/22/2033 12:06:59 PM"
loc
- the Locale to be used.localize()
protected static int findFirstDigit(java.lang.String str)
protected static int toInt(java.lang.String str, int start, int length)
Remark: As Waba does not have String.parseInt()
a portable
simple method had to be written.
|
20080913, rgf | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |