|View script||License||Download documentation as: HTML or editable|
|Download script||History||Other scripts by: chrisrg|
Script Library: 1238 scripts
Documentation for: form-date.r
Usage document for %form-date.r
1. Introduction to %form-date.r
This library script is for inclusion in other programs and allows sophisticated date formatting, ala strftime, but not exactly
2. form-date At a Glance
>> form-date now "%A %e%i %B, %Y at %T" == "Thursday 26th April, 2007 at 00:44:12" >> form-date now "%d-%b-%Y/%H:%M:%S%Z" == "26-Apr-2007/00:49:39-04:00" >> now == 26-Apr-2007/0:52:13-4:00 >> form-date now/precise "%c" == "19-Jul-2007/00:01:45.108242-04:00"
3. Using %form-date.r
Including this function is simple. Just DO it.
>> do %form-date.r
or to execute this right out of the rebol.org library
>> do http://www.rebol.org/download-a-script.r?script-name=form-date.rYou now have the form-date function
>> help form-date USAGE: FORM-DATE date format /gmt DESCRIPTION: Renders a date to a given format (largely compatible with strftime) FORM-DATE is a function value. ARGUMENTS: date -- (Type: date) format -- (Type: any-string) REFINEMENTS: /gmt -- Align time with GMT
4. The format string
Ordinary characters placed in the format string are inserted into return value without conversion. Conversion specifications are introduced by a % character, and terminated by a conversion specifier character, and are replaced and inserted into return value as follows:
5. What you can learn
The interpolate function, along with date-codes is an excellent example of parse. The dialect created is the two character format specifiers that produce the date and time pieces. A strftime dialect.
REBOL can emulate the functionality of other systems, while still remaining REBOL.
REBOL code can look world-class elegant when properly formatted and factored.
6. What you can break
The date! parameter has to be a date!. If you use any time related format specifiers, it has to be a date! that includes time information or returned fields may be incorrect.
>> form-date now/date "%T" == "00:00:00" >> form-date now/time "%T" Script Error: form-date expected date argument of type: date Near: form-date now/time "%T" >> form-date now "%T" == "02:29:39"
7. What's new
With the addition of %c, you have clean, always the same length REBOL time-stamps.
>> 01-Jan-0001/00:00:00.000000-00:00 == 1-Jan-0001/0:00 >> form-date 01-Jan-0001/00:00:00.000000-00:00 "%c" == "01-Jan-0001/00:00:00.000000+00:00" >> form-date now/precise "%c" == "19-Jul-2007/00:42:53.586560-04:00" >> form-date now "%c" == "19-Jul-2007/00:43:19.000000-04:00"
7.1. Precision versus Accuracy
Please note that now/precise while reporting 6 digit precision for the sub-seconds, is only as accurate as your computer clock will allow.