This is an inbuilt function function provided by PPWIZARD.
The purpose of this routine is to format a time stamp
(such as that returned by TimeStamp()
or GetFileTimeStamp())
into a "pretty" text format.
It can be configured to support any language and you can also configure
how a date and time look by default.
The return code is the formatted value.
If you can't work out what is happening turn debug on.
This routine takes parameters as follows:
- FormatSpec
This is a string which contains codes which will get
replaced by date/time information (more detail below).
If not supplied a default format is used, the default
can be modified with the
"*_DEFAULT_TIME_FORMAT"
(see below about configuration).
- TimeStamp
This is a timestamp of the form "YYYYMMDDHHMMSS".
If not supplied the current date and time is used.
- ConfigSet
This can be used to configure this routine, the default
value is "FORMATTIME" (more detail below).
This is a string which may contain two character long control codes
(all of which begin with "%"), if the control code is
not recognised then it is ignored.
In the following examples are shown in red
(based on the current time (Sat Feb 17 2007 at 10:37:26am),
available codes are:
- %a
This is replaced with the short weekday.
An example of what might be returned is "Sat".
- %A
This is replaced with the full weekday.
An example of what might be returned is "Saturday".
- %b
This is replaced with the short month name.
An example of what might be returned is "Feb".
- %B
This is replaced with the full month name.
An example of what might be returned is "February".
- %d
This is replaced with the day of the month
(01-31).
An example of what might be returned is "17".
- %e
This is replaced with the day of the month (always 2 characters)
(' 1' - '31').
An example of what might be returned is "17".
- %#
This is replaced with the day of the month
(1-31).
An example of what might be returned is "17".
- %H
This is replaced with the hour
(00-23).
An example of what might be returned is "10".
- %!
This is replaced with the hour
(0-23).
An example of what might be returned is "10".
- %I
This is replaced with the am/pm hour
(01-12).
An example of what might be returned is "10".
- %@
This is replaced with the am/pm hour
(1-12).
An example of what might be returned is "10".
- %j
This is replaced with the day of the year
(001-366).
An example of what might be returned is "048".
- %$
This is replaced with the day of the year
(1-366).
An example of what might be returned is "48".
- %m
This is replaced with the month number
(01-12).
An example of what might be returned is "02".
- %M
This is replaced with the minute number
(00-59).
An example of what might be returned is "37".
- %p
This is replaced with the "am" or "pm" text
(the values of which are configurable).
An example of what might be returned is "am".
- %S
This is replaced with the seconds number
(01-61).
An example of what might be returned is "26".
- %y
This is replaced with the last 2 digits of the year.
An example of what might be returned is "07".
- %Y
This is replaced with the full 4 digit year.
An example of what might be returned is "2007".
- %c
This is replaced with the date and time.
The format of this value is completely configurable.
An example of what might be returned is "Sat Feb 17 2007 at 10:37:26am".
- %x
This is replaced with a formatted date.
The format of this value is completely configurable.
An example of what might be returned is "Sat Feb 17 2007".
- %X
This is replaced with a formatted time.
The format of this value is completely configurable.
An example of what might be returned is "10:37:26am".
- %D
This is replaced with "%m/%d/%y"
An example of what might be returned is "02/17/07".
- %r
This is replaced with "%I:%M:%S%p".
An example of what might be returned is "10:37:26am".
- %R
This is replaced with "%H:%M".
An example of what might be returned is "10:37".
- %T
This is replaced with "%H:%M:%S".
An example of what might be returned is "10:37:26".
- %v
This is replaced with "%e-%b-%Y".
An example of what might be returned is "17-Feb-2007".
- %Z
Expands to nothing.
- %_
Expands to a single space.
- %%
This is used if you want a percent sign.
You can configure the text used for the day or month names
(to support other languages such as German) or alter the format of
some of the codes.
You do this by defining certain macros, the "ConfigSet" parameter
is the prefix for a set of these variables.
The idea is that this makes it easy for you to define multiple
languages and/or formats and switch between them easily.
The configuration macros are (* replaced by "ConfigSet" value):
- *_DAY_NAMES_SHORT
This holds the 7 short days text.
These are space separated and start with "Mon".
- *_DAY_NAMES_LONG
This holds the 7 days text.
These are space separated and start with "Monday".
- *_MONTH_NAMES_SHORT
This holds the 12 short month text.
These are space separated and start with "Jan".
- *_MONTH_NAMES_LONG
This holds the 12 months text.
These are space separated and start with "January".
- *_AM_TEXT
The text for "AM".
- *_PM_TEXT
The text for "PM".
- *_DATE_TIME_FORMAT
The date and time format as used by the
"%c" code.
- *_DATE_FORMAT
The date format as used by the
"%x" code.
- *_TIME_FORMAT
The time format as used by the
"%X" code.
This is a sample of a macro which will return the date/time of a file
in the format you specify:
;--- Create macro to get a file date/time in FormatTime() format ---
#NextId ;;Make sure temp variables will not clash...
#( ''
#define GetFileDateTime
;--- The date/time of file is "input", so make sure PPWIZARD knows ---
#DependsOn INPUT "{$File}"
;--- Work out date/time in required format ---
#evaluate @@TmpDateTime ^FormatTime("{$Fmt=^%v^}", GetFileTimeStamp("{$File}", "D"))^
;--- Generate the generated time ---
<$@@TmpDateTime>
;--- No longer need the definition ---
#undef @@TmpDateTime
#)
;--- Try the macro ---
File date is <$GetFileDateTime File="<?InputComponent>">
File date/time is <$GetFileDateTime File="<?InputComponent>" Fmt="%c">
File time is <$GetFileDateTime File="<?InputComponent>" Fmt="%X">
This is some test code, apart from anything else it works/demonstrates
each format:
;--- Get date/time of a specific file ---
#DefineRexx ''
@@File = "1.in"
@@Ts = GetFileTimeStamp(@@File)
if @@Ts = -1 then
ToFile = 'The file "' || @@File || '" does not exist!'
else
do
@@Formatted = FormatTime("%c", @@Ts);
ToFile = 'The file "' || @@File || '" is dated ' || @@Formatted
end;
#DefineRexx
=======================
<??ToFile>
=======================
;--- Test Each code ---
;#define FORMATTIME_TIME_FORMAT %I:%Mp
#NextId
#DefineRexx 'TestCode'
@@Codes = '{$#1}';
@@Result = FormatTime(@@Codes)
@@Show = 'The code "' || @@Codes || '" was replaced with "' || @@Result || '"'
call say @@Show
ToFile = ToFile || @@Show || '<' || '?NewLine>'
#DefineRexx
#DefineRexx ''
ToFile = '';
<$TestCode "%%">
<$TestCode "%a">
<$TestCode "%A">
<$TestCode "%b">
<$TestCode "%B">
<$TestCode "%d">
<$TestCode "%e">
<$TestCode "%#">
<$TestCode "%H">
<$TestCode "%!">
<$TestCode "%I">
<$TestCode "%@">
<$TestCode "%j">
<$TestCode "%$">
<$TestCode "%m">
<$TestCode "%M">
<$TestCode "%p">
<$TestCode "%S">
<$TestCode "%y">
<$TestCode "%Y">
<$TestCode "%c">
<$TestCode "%x">
<$TestCode "%X">
<$TestCode "%D">
<$TestCode "%r">
<$TestCode "%R">
<$TestCode "%T">
<$TestCode "%v">
<$TestCode "%Z">
ToFile = ToFile || d2c(10)
#DefineRexx
<?NewLine>
<?NewLine>
=======================
<??ToFile>
=======================
PPWIZARD Manual

Saturday February 17 2007 at 10:36am